take only the first address returned by host
[sliver-openvswitch.git] / lib / jsonrpc.c
index 1ea5398..e02f035 100644 (file)
@@ -26,6 +26,7 @@
 #include "json.h"
 #include "list.h"
 #include "ofpbuf.h"
+#include "ovs-thread.h"
 #include "poll-loop.h"
 #include "reconnect.h"
 #include "stream.h"
@@ -41,6 +42,7 @@ struct jsonrpc {
 
     /* Input. */
     struct byteq input;
+    uint8_t input_buffer[512];
     struct json_parser *parser;
     struct jsonrpc_msg *received;
 
@@ -87,7 +89,7 @@ jsonrpc_open(struct stream *stream)
     rpc = xzalloc(sizeof *rpc);
     rpc->name = xstrdup(stream_get_name(stream));
     rpc->stream = stream;
-    byteq_init(&rpc->input);
+    byteq_init(&rpc->input, rpc->input_buffer, sizeof rpc->input_buffer);
     list_init(&rpc->output);
 
     return rpc;
@@ -129,7 +131,7 @@ jsonrpc_run(struct jsonrpc *rpc)
         } else {
             if (retval != -EAGAIN) {
                 VLOG_WARN_RL(&rl, "%s: send error: %s",
-                             rpc->name, strerror(-retval));
+                             rpc->name, ovs_strerror(-retval));
                 jsonrpc_error(rpc, -retval);
             }
             break;
@@ -307,7 +309,7 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
                     return EAGAIN;
                 } else {
                     VLOG_WARN_RL(&rl, "%s: receive error: %s",
-                                 rpc->name, strerror(-retval));
+                                 rpc->name, ovs_strerror(-retval));
                     jsonrpc_error(rpc, -retval);
                     return rpc->status;
                 }
@@ -330,7 +332,7 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
                 jsonrpc_received(rpc);
                 if (rpc->status) {
                     const struct byteq *q = &rpc->input;
-                    if (q->head <= BYTEQ_SIZE) {
+                    if (q->head <= q->size) {
                         stream_report_content(q->buffer, q->head,
                                               STREAM_JSONRPC,
                                               THIS_MODULE, rpc->name);
@@ -350,7 +352,7 @@ void
 jsonrpc_recv_wait(struct jsonrpc *rpc)
 {
     if (rpc->status || rpc->received || !byteq_is_empty(&rpc->input)) {
-        (poll_immediate_wake)(rpc->name);
+        poll_immediate_wake_at(rpc->name);
     } else {
         stream_recv_wait(rpc->stream);
     }
@@ -513,8 +515,11 @@ jsonrpc_create(enum jsonrpc_msg_type type, const char *method,
 static struct json *
 jsonrpc_create_id(void)
 {
-    static unsigned int id;
-    return json_integer_create(id++);
+    static atomic_uint next_id = ATOMIC_VAR_INIT(0);
+    unsigned int id;
+
+    atomic_add(&next_id, 1, &id);
+    return json_integer_create(id);
 }
 
 struct jsonrpc_msg *
@@ -1116,7 +1121,8 @@ jsonrpc_session_set_dscp(struct jsonrpc_session *s,
             error = pstream_set_dscp(s->pstream, dscp);
             if (error) {
                 VLOG_ERR("%s: failed set_dscp %s",
-                         reconnect_get_name(s->reconnect), strerror(error));
+                         reconnect_get_name(s->reconnect),
+                         ovs_strerror(error));
             }
             /*
              * XXX race window between setting dscp to listening socket