示例#1
0
文件: jsonrpc.c 项目: rafaelfonte/ovs
/* Creates and returns a jsonrpc_session to 'name', which should be a string
 * acceptable to stream_open() or pstream_open().
 *
 * If 'name' is an active connection method, e.g. "tcp:127.1.2.3", the new
 * jsonrpc_session connects to 'name'.  If 'retry' is true, then the new
 * session connects and reconnects to 'name', with backoff.  If 'retry' is
 * false, the new session will only try to connect once and after a connection
 * failure or a disconnection jsonrpc_session_is_alive() will return false for
 * the new session.
 *
 * If 'name' is a passive connection method, e.g. "ptcp:", the new
 * jsonrpc_session listens for connections to 'name'.  It maintains at most one
 * connection at any given time.  Any new connection causes the previous one
 * (if any) to be dropped. */
struct jsonrpc_session *
jsonrpc_session_open(const char *name, bool retry)
{
    struct jsonrpc_session *s;

    s = xmalloc(sizeof *s);
    s->reconnect = reconnect_create(time_msec());
    reconnect_set_name(s->reconnect, name);
    reconnect_enable(s->reconnect, time_msec());
    s->rpc = NULL;
    s->stream = NULL;
    s->pstream = NULL;
    s->seqno = 0;
    s->dscp = 0;
    s->last_error = 0;

    if (!pstream_verify_name(name)) {
        reconnect_set_passive(s->reconnect, true, time_msec());
    } else if (!retry) {
        reconnect_set_max_tries(s->reconnect, 1);
        reconnect_set_backoff(s->reconnect, INT_MAX, INT_MAX);
    }

    if (!stream_or_pstream_needs_probes(name)) {
        reconnect_set_probe_interval(s->reconnect, 0);
    }

    return s;
}
示例#2
0
文件: jsonrpc.c 项目: enukane/ovs
/* Creates and returns a jsonrpc_session to 'name', which should be a string
 * acceptable to stream_open() or pstream_open().
 *
 * If 'name' is an active connection method, e.g. "tcp:127.1.2.3", the new
 * jsonrpc_session connects and reconnects, with back-off, to 'name'.
 *
 * If 'name' is a passive connection method, e.g. "ptcp:", the new
 * jsonrpc_session listens for connections to 'name'.  It maintains at most one
 * connection at any given time.  Any new connection causes the previous one
 * (if any) to be dropped. */
struct jsonrpc_session *
jsonrpc_session_open(const char *name)
{
    struct jsonrpc_session *s;

    s = xmalloc(sizeof *s);
    s->reconnect = reconnect_create(time_msec());
    reconnect_set_name(s->reconnect, name);
    reconnect_enable(s->reconnect, time_msec());
    s->rpc = NULL;
    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;
}