Refactor jsonrpc_session_recv_until() to return the results of the jsonrpc_recv()/jsonrpc_recv_until() calls, making it possible to detect blocking calls (EAGAIN) in upper layers.
Signed-off-by: Martin Morgenstern <martin.morgenst...@cloudandheat.com> --- lib/jsonrpc.c | 22 +++++++++++++++------- lib/jsonrpc.h | 4 ++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index c2bd72408..b02725a10 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -1269,18 +1269,21 @@ jsonrpc_session_send(struct jsonrpc_session *s, struct jsonrpc_msg *msg) } } -struct jsonrpc_msg * -jsonrpc_session_recv_until(struct jsonrpc_session *s, long long deadline) +int +jsonrpc_session_recv_until(struct jsonrpc_session *s, + struct jsonrpc_msg **full_msg, + long long deadline) { if (s->rpc) { unsigned int received_bytes; struct jsonrpc_msg *msg; + int ret; received_bytes = jsonrpc_get_received_bytes(s->rpc); if (deadline) { - jsonrpc_recv_until(s->rpc, &msg, deadline); + ret = jsonrpc_recv_until(s->rpc, &msg, deadline); } else { - jsonrpc_recv(s->rpc, &msg); + ret = jsonrpc_recv(s->rpc, &msg); } long long int now = time_msec(); @@ -1306,18 +1309,23 @@ jsonrpc_session_recv_until(struct jsonrpc_session *s, long long deadline) && !strcmp(msg->id->string, "echo")) { /* It's a reply to our echo request. Suppress it. */ } else { - return msg; + *full_msg = msg; + return 0; } jsonrpc_msg_destroy(msg); + } else { + return ret; } } - return NULL; + return 0; } struct jsonrpc_msg * jsonrpc_session_recv(struct jsonrpc_session *s) { - return jsonrpc_session_recv_until(s, 0); + struct jsonrpc_msg *msg = NULL; + jsonrpc_session_recv_until(s, &msg, 0); + return msg; } void diff --git a/lib/jsonrpc.h b/lib/jsonrpc.h index 09a4b0fd1..482d4d9a0 100644 --- a/lib/jsonrpc.h +++ b/lib/jsonrpc.h @@ -126,8 +126,8 @@ size_t jsonrpc_session_get_n_remotes(const struct jsonrpc_session *); int jsonrpc_session_send(struct jsonrpc_session *, struct jsonrpc_msg *); struct jsonrpc_msg *jsonrpc_session_recv(struct jsonrpc_session *); -struct jsonrpc_msg *jsonrpc_session_recv_until(struct jsonrpc_session *, - long long); +int jsonrpc_session_recv_until(struct jsonrpc_session *, struct jsonrpc_msg **, + long long); void jsonrpc_session_recv_wait(struct jsonrpc_session *); bool jsonrpc_session_is_alive(const struct jsonrpc_session *); -- 2.45.2 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev