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>
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;
}
}
- *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