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 *
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;
int jsonrpc_get_status(const struct jsonrpc *);
size_t jsonrpc_get_backlog(const struct jsonrpc *);
+unsigned int jsonrpc_get_received_bytes(const struct jsonrpc *);
const char *jsonrpc_get_name(const struct jsonrpc *);
int jsonrpc_send(struct jsonrpc *, struct jsonrpc_msg *);
self.input = ""
self.output = ""
self.parser = None
+ self.received_bytes = 0
def close(self):
self.stream.close()
else:
return len(self.output)
+ def get_received_bytes(self):
+ return self.received_bytes
+
def __log_msg(self, title, msg):
vlog.dbg("%s: %s %s" % (self.name, title, msg))
return EOF, None
else:
self.input += data
+ self.received_bytes += len(data)
else:
if self.parser is None:
self.parser = ovs.json.Parser()
self.pstream = None
if self.rpc:
+ received_bytes = self.rpc.get_received_bytes()
self.rpc.run()
+ if received_bytes != self.rpc.get_received_bytes():
+ # 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.
+ self.reconnect.activity(ovs.timeval.msec())
+
error = self.rpc.get_status()
if error != 0:
self.reconnect.disconnected(ovs.timeval.msec(), error)