Browse Source

Add debugging and sanity checks to send_json_msg.

master
Con Kolivas 7 years ago
parent
commit
6b24581263
  1. 21
      src/ckpool.c
  2. 3
      src/ckpool.h

21
src/ckpool.c

@ -961,21 +961,36 @@ static void terminate_oldpid(const ckpool_t *ckp, proc_instance_t *pi, const pid
} }
/* This is for blocking sends of json messages */ /* This is for blocking sends of json messages */
bool send_json_msg(connsock_t *cs, const json_t *json_msg) bool _send_json_msg(connsock_t *cs, const json_t *json_msg, const char *file, const char *func, const int line)
{ {
bool ret = false;
int len, sent; int len, sent;
char *s; char *s;
if (unlikely(!json_msg)) {
LOGWARNING("Empty json msg in send_json_msg from %s %s:%d", file, func, line);
goto out;
}
s = json_dumps(json_msg, JSON_ESCAPE_SLASH | JSON_EOL); s = json_dumps(json_msg, JSON_ESCAPE_SLASH | JSON_EOL);
if (unlikely(!s)) {
LOGWARNING("Empty json dump in send_json_msg from %s %s:%d", file, func, line);
goto out;
}
LOGDEBUG("Sending json msg: %s", s); LOGDEBUG("Sending json msg: %s", s);
len = strlen(s); len = strlen(s);
if (unlikely(!len)) {
LOGWARNING("Zero length string in send_json_msg from %s %s:%d", file, func, line);
goto out;
}
sent = write_socket(cs->fd, s, len); sent = write_socket(cs->fd, s, len);
dealloc(s); dealloc(s);
if (sent != len) { if (sent != len) {
LOGNOTICE("Failed to send %d bytes sent %d in send_json_msg", len, sent); LOGNOTICE("Failed to send %d bytes sent %d in send_json_msg", len, sent);
return false; goto out;
} }
return true; ret = true;
out:
return ret;
} }
/* Decode a string that should have a json message and return just the contents /* Decode a string that should have a json message and return just the contents

3
src/ckpool.h

@ -372,7 +372,8 @@ char *_ckdb_msg_call(const ckpool_t *ckp, const char *msg, const char *file, co
json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); json_t *json_rpc_call(connsock_t *cs, const char *rpc_req);
json_t *json_rpc_response(connsock_t *cs, const char *rpc_req); json_t *json_rpc_response(connsock_t *cs, const char *rpc_req);
void json_rpc_msg(connsock_t *cs, const char *rpc_req); void json_rpc_msg(connsock_t *cs, const char *rpc_req);
bool send_json_msg(connsock_t *cs, const json_t *json_msg); bool _send_json_msg(connsock_t *cs, const json_t *json_msg, const char *file, const char *func, const int line);
#define send_json_msg(CS, JSON_MSG) _send_json_msg(CS, JSON_MSG, __FILE__, __func__, __LINE__)
json_t *json_result(json_t *val); json_t *json_result(json_t *val);
json_t *json_errval(json_t *val); json_t *json_errval(json_t *val);
json_t *json_msg_result(const char *msg, json_t **res_val, json_t **err_val); json_t *json_msg_result(const char *msg, json_t **res_val, json_t **err_val);

Loading…
Cancel
Save