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:
parent
6397801009
commit
122a776326
@ -260,7 +260,7 @@ spdk_jsonrpc_server_handle_error(struct spdk_jsonrpc_request *request, int error
|
||||
static int
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
rc = spdk_jsonrpc_parse_request(conn, conn->recv_buf, conn->recv_len);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("jsonrpc parse request failed\n");
|
||||
return -1;
|
||||
}
|
||||
offset = 0;
|
||||
do {
|
||||
rc = spdk_jsonrpc_parse_request(conn, conn->recv_buf + offset, conn->recv_len - offset);
|
||||
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
|
||||
* parsed request down to the beginning.
|
||||
* Successfully parsed a requests - move any data past the end of the
|
||||
* parsed requests down to the beginning.
|
||||
*/
|
||||
assert((size_t)rc <= conn->recv_len);
|
||||
memmove(conn->recv_buf, conn->recv_buf + rc, conn->recv_len - rc);
|
||||
conn->recv_len -= rc;
|
||||
assert((size_t)offset <= conn->recv_len);
|
||||
memmove(conn->recv_buf, conn->recv_buf + offset, conn->recv_len - offset);
|
||||
conn->recv_len -= offset;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user