aboutsummaryrefslogtreecommitdiff
path: root/lib/jsonrpc.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2012-04-24 10:57:41 -0700
committerBen Pfaff <blp@nicira.com>2012-04-25 15:17:31 -0700
commit3a4548cfb2fb7e7344618f449ab9bf651ef83e6b (patch)
tree80c0c73d778978ce152304a9481097f74659733d /lib/jsonrpc.c
parent896b32721d2d7a0bf0d032e174d066965cfa2b83 (diff)
jsonrpc: Keep jsonrpc_recv() from taking over the CPU.
jsonrpc_recv() could take an unbounded amount of CPU time as long as data kept arriving, preventing other work from taking place. This limits the amount of work to processing at most 25 kB of received data and then yielding to the caller. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/jsonrpc.c')
-rw-r--r--lib/jsonrpc.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index fc8a75b0..4ebff104 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -277,13 +277,19 @@ jsonrpc_send(struct jsonrpc *rpc, struct jsonrpc_msg *msg)
int
jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
{
+ int i;
+
*msgp = NULL;
if (rpc->status) {
return rpc->status;
}
- while (!rpc->received) {
- if (byteq_is_empty(&rpc->input)) {
+ for (i = 0; i < 50; i++) {
+ if (rpc->received) {
+ *msgp = rpc->received;
+ rpc->received = NULL;
+ return 0;
+ } else if (byteq_is_empty(&rpc->input)) {
size_t chunk;
int retval;
@@ -328,9 +334,7 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
}
}
- *msgp = rpc->received;
- rpc->received = NULL;
- return 0;
+ return EAGAIN;
}
/* Causes the poll loop to wake up when jsonrpc_recv() may return a value other