Previously, if the final iteration of the loop in jsonrpc_recv reads or
parses the last portion of a json object, it will return EAGAIN, with
the next call to jsonrpc_recv setting the message pointer. This can be
problematic if external code uses this function in conjunction with a
check on the socket's file descripitor. With this change, the loop does
not end if the byte queue is non-empty unless the parser has completed,
in which case the message pointer will always be set to the parsed
message.
Signed-off-by: Chris Hydon<chy...@aristanetworks.com>
---
lib/jsonrpc.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index bda0f7f..84d4e52 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -292,12 +292,8 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg
**msgp)
return rpc->status;
}
- for (i = 0; i < 50; i++) {
- if (rpc->received) {
- *msgp = rpc->received;
- rpc->received = NULL;
- return 0;
- } else if (byteq_is_empty(&rpc->input)) {
+ for (i = 0; (i < 50 || !byteq_is_empty(&rpc->input)) && !rpc->received;
i++) {
+ if (byteq_is_empty(&rpc->input)) {
size_t chunk;
int retval;
@@ -342,6 +338,11 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
}
}
+ if (rpc->received) {
+ *msgp = rpc->received;
+ rpc->received = NULL;
+ return 0;
+ }
return EAGAIN;
}
-- 1.7.4.4
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev