~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/jsonrpc.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "json.h"
27
27
#include "list.h"
28
28
#include "ofpbuf.h"
 
29
#include "ovs-thread.h"
29
30
#include "poll-loop.h"
30
31
#include "reconnect.h"
31
32
#include "stream.h"
41
42
 
42
43
    /* Input. */
43
44
    struct byteq input;
 
45
    uint8_t input_buffer[512];
44
46
    struct json_parser *parser;
45
47
    struct jsonrpc_msg *received;
46
48
 
87
89
    rpc = xzalloc(sizeof *rpc);
88
90
    rpc->name = xstrdup(stream_get_name(stream));
89
91
    rpc->stream = stream;
90
 
    byteq_init(&rpc->input);
 
92
    byteq_init(&rpc->input, rpc->input_buffer, sizeof rpc->input_buffer);
91
93
    list_init(&rpc->output);
92
94
 
93
95
    return rpc;
129
131
        } else {
130
132
            if (retval != -EAGAIN) {
131
133
                VLOG_WARN_RL(&rl, "%s: send error: %s",
132
 
                             rpc->name, strerror(-retval));
 
134
                             rpc->name, ovs_strerror(-retval));
133
135
                jsonrpc_error(rpc, -retval);
134
136
            }
135
137
            break;
307
309
                    return EAGAIN;
308
310
                } else {
309
311
                    VLOG_WARN_RL(&rl, "%s: receive error: %s",
310
 
                                 rpc->name, strerror(-retval));
 
312
                                 rpc->name, ovs_strerror(-retval));
311
313
                    jsonrpc_error(rpc, -retval);
312
314
                    return rpc->status;
313
315
                }
330
332
                jsonrpc_received(rpc);
331
333
                if (rpc->status) {
332
334
                    const struct byteq *q = &rpc->input;
333
 
                    if (q->head <= BYTEQ_SIZE) {
 
335
                    if (q->head <= q->size) {
334
336
                        stream_report_content(q->buffer, q->head,
335
337
                                              STREAM_JSONRPC,
336
338
                                              THIS_MODULE, rpc->name);
513
515
static struct json *
514
516
jsonrpc_create_id(void)
515
517
{
516
 
    static unsigned int id;
517
 
    return json_integer_create(id++);
 
518
    static atomic_uint next_id = ATOMIC_VAR_INIT(0);
 
519
    unsigned int id;
 
520
 
 
521
    atomic_add(&next_id, 1, &id);
 
522
    return json_integer_create(id);
518
523
}
519
524
 
520
525
struct jsonrpc_msg *
1116
1121
            error = pstream_set_dscp(s->pstream, dscp);
1117
1122
            if (error) {
1118
1123
                VLOG_ERR("%s: failed set_dscp %s",
1119
 
                         reconnect_get_name(s->reconnect), strerror(error));
 
1124
                         reconnect_get_name(s->reconnect),
 
1125
                         ovs_strerror(error));
1120
1126
            }
1121
1127
            /*
1122
1128
             * XXX race window between setting dscp to listening socket