diff options
author | Ben Pfaff <blp@nicira.com> | 2012-09-05 13:34:35 -0700 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2012-09-07 10:50:21 -0700 |
commit | 3a8d38c88e26f9f76f3c60efbcbead02240c26d0 (patch) | |
tree | 80514af1c9b6720c6929f23bbf162589f4d77fc2 /lib/jsonrpc.c | |
parent | f97cae29996cf17190f4ba5cdc62e9abf4386cb6 (diff) |
jsonrpc: Treat receiving part of a message as activity.
Until now, the jsonrpc code has only counted receiving a full JSON-RPC
messages as activity. This could theoretically time out, then, while a
very long message is in transit or if a slow link is involved. This commit
changes this code to count receiving any part of a message as activity.
This isn't a problem for OpenFlow connections because OpenFlow messages are
at most 64 kB in size.
This problem hasn't actually been observed in practice.
Bug #12789.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/jsonrpc.c')
-rw-r--r-- | lib/jsonrpc.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index 27b46c6d..0e1788ca 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -178,6 +178,14 @@ jsonrpc_get_backlog(const struct jsonrpc *rpc) return rpc->status ? 0 : rpc->backlog; } +/* Returns the number of bytes that have been received on 'rpc''s underlying + * stream. (The value wraps around if it exceeds UINT_MAX.) */ +unsigned int +jsonrpc_get_received_bytes(const struct jsonrpc *rpc) +{ + return rpc->input.head; +} + /* Returns 'rpc''s name, that is, the name returned by stream_get_name() for * the stream underlying 'rpc' when 'rpc' was created. */ const char * @@ -988,10 +996,21 @@ struct jsonrpc_msg * jsonrpc_session_recv(struct jsonrpc_session *s) { if (s->rpc) { + unsigned int received_bytes; struct jsonrpc_msg *msg; + + received_bytes = jsonrpc_get_received_bytes(s->rpc); jsonrpc_recv(s->rpc, &msg); - if (msg) { + if (received_bytes != jsonrpc_get_received_bytes(s->rpc)) { + /* Data was successfully received. + * + * Previously we only counted receiving a full message as activity, + * but with large messages or a slow connection that policy could + * time out the session mid-message. */ reconnect_activity(s->reconnect, time_msec()); + } + + if (msg) { if (msg->type == JSONRPC_REQUEST && !strcmp(msg->method, "echo")) { /* Echo request. Send reply. */ struct jsonrpc_msg *reply; |