Skip to content

Commit e3fae33

Browse files
chenchachaguanqiao
authored andcommitted
Fix a bug: the connect can't close after the response sent
Signed-off-by: chenchacha <chen.chenchacha@foxmail.com>
1 parent a127445 commit e3fae33

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/jsonrpc-c.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ static void *get_in_addr(struct sockaddr *sa) {
3333
}
3434

3535
static int send_response(struct jrpc_connection * conn, char *response) {
36+
int l, len, send;
3637
int fd = conn->fd;
3738
if (conn->debug_level > 1)
3839
printf("JSON Response:\n%s\n", response);
39-
write(fd, response, strlen(response));
40+
41+
for (send = 0, len = strlen(response); send < len; send += l) {
42+
l = write(fd, response+send, len - send);
43+
if (l < 0)
44+
break;
45+
}
46+
4047
write(fd, "\n", 1);
4148
return 0;
4249
}
@@ -236,6 +243,7 @@ static void connection_cb(struct ev_loop *loop, ev_io *w, int revents) {
236243
}
237244
}
238245

246+
return close_connection(loop, w);
239247
}
240248

241249
static void accept_cb(struct ev_loop *loop, ev_io *w, int revents) {

0 commit comments

Comments
 (0)