jsonrpc: process all requests in buffer

If more than one full request is received by a single recv() call only
first one will be parsed. Then next time we call recv() is called it
will return EAGAIN and next request won't be parsed. Fix this by always
parsing all requests in the buffer.

Change-Id: I0a2c72fd0ad6184834b9831bda520a28ab815f0d
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/437161
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Maciej Szwed <maciej.szwed@intel.com>
Reviewed-by: wuzhouhui <wuzhouhui@kingsoft.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
Pawel Wodkowski 2018-12-13 15:00:12 +01:00 committed by Jim Harris
parent 6397801009
commit 122a776326

View File

@ -260,7 +260,7 @@ spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_request *request, int error
static int static int
spdk_jsonrpc_server_conn_recv(struct spdk_jsonrpc_server_conn *conn) spdk_jsonrpc_server_conn_recv(struct spdk_jsonrpc_server_conn *conn)
{ {
ssize_t rc; ssize_t rc, offset;
size_t recv_avail = SPDK_JSONRPC_RECV_BUF_SIZE - conn->recv_len; size_t recv_avail = SPDK_JSONRPC_RECV_BUF_SIZE - conn->recv_len;
rc = recv(conn->sockfd, conn->recv_buf + conn->recv_len, recv_avail, 0); rc = recv(conn->sockfd, conn->recv_buf + conn->recv_len, recv_avail, 0);
@ -279,20 +279,25 @@ spdk_jsonrpc_server_conn_recv(struct spdk_jsonrpc_server_conn *conn)
conn->recv_len += rc; conn->recv_len += rc;
rc = spdk_jsonrpc_parse_request(conn, conn->recv_buf, conn->recv_len); offset = 0;
if (rc < 0) { do {
SPDK_ERRLOG("jsonrpc parse request failed\n"); rc = spdk_jsonrpc_parse_request(conn, conn->recv_buf + offset, conn->recv_len - offset);
return -1; if (rc < 0) {
} SPDK_ERRLOG("jsonrpc parse request failed\n");
return -1;
}
if (rc > 0) { offset += rc;
} while (rc > 0);
if (offset > 0) {
/* /*
* Successfully parsed a request - move any data past the end of the * Successfully parsed a requests - move any data past the end of the
* parsed request down to the beginning. * parsed requests down to the beginning.
*/ */
assert((size_t)rc <= conn->recv_len); assert((size_t)offset <= conn->recv_len);
memmove(conn->recv_buf, conn->recv_buf + rc, conn->recv_len - rc); memmove(conn->recv_buf, conn->recv_buf + offset, conn->recv_len - offset);
conn->recv_len -= rc; conn->recv_len -= offset;
} }
return 0; return 0;