X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=lib%2Fjsonrpc.c;h=57613697779a6a35d648f631ebca110e031cd857;hb=41792464296d4ea9393adff3eea7bef514655cba;hp=764677114d4fa1ed32046d3bf4faaba28e56ea0a;hpb=78fdd76d907f62255b3db02ea90e540f4a2b006b;p=openvswitch diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c index 76467711..57613697 100644 --- a/lib/jsonrpc.c +++ b/lib/jsonrpc.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks. + * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,19 +60,20 @@ static void jsonrpc_error(struct jsonrpc *, int error); /* This is just the same as stream_open() except that it uses the default * JSONRPC ports if none is specified. */ int -jsonrpc_stream_open(const char *name, struct stream **streamp) +jsonrpc_stream_open(const char *name, struct stream **streamp, uint8_t dscp) { return stream_open_with_default_ports(name, JSONRPC_TCP_PORT, - JSONRPC_SSL_PORT, streamp); + JSONRPC_SSL_PORT, streamp, + dscp); } /* This is just the same as pstream_open() except that it uses the default * JSONRPC ports if none is specified. */ int -jsonrpc_pstream_open(const char *name, struct pstream **pstreamp) +jsonrpc_pstream_open(const char *name, struct pstream **pstreamp, uint8_t dscp) { return pstream_open_with_default_ports(name, JSONRPC_TCP_PORT, - JSONRPC_SSL_PORT, pstreamp); + JSONRPC_SSL_PORT, pstreamp, dscp); } /* Returns a new JSON-RPC stream that uses 'stream' for input and output. The @@ -276,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; @@ -327,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 @@ -412,9 +417,11 @@ jsonrpc_transact_block(struct jsonrpc *rpc, struct jsonrpc_msg *request, if (!error) { for (;;) { error = jsonrpc_recv_block(rpc, &reply); - if (error - || (reply->type == JSONRPC_REPLY - && json_equal(id, reply->id))) { + if (error) { + break; + } + if ((reply->type == JSONRPC_REPLY || reply->type == JSONRPC_ERROR) + && json_equal(id, reply->id)) { break; } jsonrpc_msg_destroy(reply); @@ -731,6 +738,7 @@ struct jsonrpc_session { struct stream *stream; struct pstream *pstream; unsigned int seqno; + uint8_t dscp; }; /* Creates and returns a jsonrpc_session to 'name', which should be a string @@ -756,11 +764,16 @@ jsonrpc_session_open(const char *name) s->stream = NULL; s->pstream = NULL; s->seqno = 0; + s->dscp = 0; if (!pstream_verify_name(name)) { reconnect_set_passive(s->reconnect, true, time_msec()); } + if (!stream_or_pstream_needs_probes(name)) { + reconnect_set_probe_interval(s->reconnect, 0); + } + return s; } @@ -780,6 +793,7 @@ jsonrpc_session_open_unreliably(struct jsonrpc *jsonrpc) reconnect_set_name(s->reconnect, jsonrpc_get_name(jsonrpc)); reconnect_set_max_tries(s->reconnect, 0); reconnect_connected(s->reconnect, time_msec()); + s->dscp = 0; s->rpc = jsonrpc; s->stream = NULL; s->pstream = NULL; @@ -823,12 +837,13 @@ jsonrpc_session_connect(struct jsonrpc_session *s) jsonrpc_session_disconnect(s); if (!reconnect_is_passive(s->reconnect)) { - error = jsonrpc_stream_open(name, &s->stream); + error = jsonrpc_stream_open(name, &s->stream, s->dscp); if (!error) { reconnect_connecting(s->reconnect, time_msec()); } } else { - error = s->pstream ? 0 : jsonrpc_pstream_open(name, &s->pstream); + error = s->pstream ? 0 : jsonrpc_pstream_open(name, &s->pstream, + s->dscp); if (!error) { reconnect_listening(s->reconnect, time_msec()); } @@ -1039,3 +1054,13 @@ jsonrpc_session_set_probe_interval(struct jsonrpc_session *s, { reconnect_set_probe_interval(s->reconnect, probe_interval); } + +void +jsonrpc_session_set_dscp(struct jsonrpc_session *s, + uint8_t dscp) +{ + if (s->dscp != dscp) { + s->dscp = dscp; + jsonrpc_session_force_reconnect(s); + } +}