|
|
@ -85,13 +85,17 @@ out: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Invalidate this instance */ |
|
|
|
/* Invalidate this instance */ |
|
|
|
static void invalidate_client(client_instance_t *client) |
|
|
|
static void invalidate_client(ckpool_t *ckp, client_instance_t *client) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
char buf[256]; |
|
|
|
|
|
|
|
|
|
|
|
close(client->fd); |
|
|
|
close(client->fd); |
|
|
|
client->fd = -1; |
|
|
|
client->fd = -1; |
|
|
|
|
|
|
|
sprintf(buf, "dropclient=%d", client->id); |
|
|
|
|
|
|
|
send_proc(&ckp->stratifier, buf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void send_client(conn_instance_t *ci, int id, const char *buf); |
|
|
|
static void send_client(ckpool_t *ckp, conn_instance_t *ci, int id, const char *buf); |
|
|
|
|
|
|
|
|
|
|
|
static void parse_client_msg(conn_instance_t *ci, client_instance_t *client) |
|
|
|
static void parse_client_msg(conn_instance_t *ci, client_instance_t *client) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -113,7 +117,7 @@ retry: |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
LOGINFO("Client fd %d disconnected", client->fd); |
|
|
|
LOGINFO("Client fd %d disconnected", client->fd); |
|
|
|
invalidate_client(client); |
|
|
|
invalidate_client(ckp, client); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
client->bufofs += ret; |
|
|
|
client->bufofs += ret; |
|
|
@ -126,7 +130,7 @@ reparse: |
|
|
|
if (!eol) { |
|
|
|
if (!eol) { |
|
|
|
if (unlikely(client->bufofs > MAX_MSGSIZE)) { |
|
|
|
if (unlikely(client->bufofs > MAX_MSGSIZE)) { |
|
|
|
LOGWARNING("Client fd %d overloaded buffer without EOL, disconnecting", client->fd); |
|
|
|
LOGWARNING("Client fd %d overloaded buffer without EOL, disconnecting", client->fd); |
|
|
|
invalidate_client(client); |
|
|
|
invalidate_client(ckp, client); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (moredata) |
|
|
|
if (moredata) |
|
|
@ -138,7 +142,7 @@ reparse: |
|
|
|
buflen = eol - client->buf + 1; |
|
|
|
buflen = eol - client->buf + 1; |
|
|
|
if (unlikely(buflen > MAX_MSGSIZE)) { |
|
|
|
if (unlikely(buflen > MAX_MSGSIZE)) { |
|
|
|
LOGWARNING("Client fd %d message oversize, disconnecting", client->fd); |
|
|
|
LOGWARNING("Client fd %d message oversize, disconnecting", client->fd); |
|
|
|
invalidate_client(client); |
|
|
|
invalidate_client(ckp, client); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
memcpy(msg, client->buf, buflen); |
|
|
|
memcpy(msg, client->buf, buflen); |
|
|
@ -148,8 +152,8 @@ reparse: |
|
|
|
val = json_loads(msg, 0, NULL); |
|
|
|
val = json_loads(msg, 0, NULL); |
|
|
|
if (!val) { |
|
|
|
if (!val) { |
|
|
|
LOGINFO("Client id %d sent invalid json message %s", client->id, msg); |
|
|
|
LOGINFO("Client id %d sent invalid json message %s", client->id, msg); |
|
|
|
send_client(ci, client->id, "Invalid JSON, disconnecting\n"); |
|
|
|
send_client(ckp, ci, client->id, "Invalid JSON, disconnecting\n"); |
|
|
|
invalidate_client(client); |
|
|
|
invalidate_client(ckp, client); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
char *s; |
|
|
|
char *s; |
|
|
@ -230,7 +234,7 @@ out: |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void send_client(conn_instance_t *ci, int id, const char *buf) |
|
|
|
static void send_client(ckpool_t *ckp, conn_instance_t *ci, int id, const char *buf) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int fd = -1, ret, len, ofs = 0; |
|
|
|
int fd = -1, ret, len, ofs = 0; |
|
|
|
client_instance_t *client; |
|
|
|
client_instance_t *client; |
|
|
@ -265,7 +269,7 @@ static void send_client(conn_instance_t *ci, int id, const char *buf) |
|
|
|
if (interrupted()) |
|
|
|
if (interrupted()) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
LOGWARNING("Client id %d disconnected", id); |
|
|
|
LOGWARNING("Client id %d disconnected", id); |
|
|
|
invalidate_client(client); |
|
|
|
invalidate_client(ckp, client); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
ofs += ret; |
|
|
|
ofs += ret; |
|
|
@ -312,7 +316,7 @@ retry: |
|
|
|
dealloc(buf); |
|
|
|
dealloc(buf); |
|
|
|
buf = json_dumps(json_msg, 0); |
|
|
|
buf = json_dumps(json_msg, 0); |
|
|
|
realloc_strcat(&buf, "\n"); |
|
|
|
realloc_strcat(&buf, "\n"); |
|
|
|
send_client(ci, client_id, buf); |
|
|
|
send_client(ckp, ci, client_id, buf); |
|
|
|
json_decref(json_msg); |
|
|
|
json_decref(json_msg); |
|
|
|
close(sockd); |
|
|
|
close(sockd); |
|
|
|
|
|
|
|
|
|
|
|