X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Frconn.c;h=ea45134fea3bcaf02ec4a34a12abe104a530b9af;hb=1e86ae6f51bcc91d2fa36e4154bc6e540251eaf8;hp=8cac1696e14d82aefcb9ca556b17f2341cf13dc0;hpb=b97ba90b95c18a7b6b16fc8821b8ef3c6b61a05c;p=openvswitch diff --git a/lib/rconn.c b/lib/rconn.c index 8cac1696..ea45134f 100644 --- a/lib/rconn.c +++ b/lib/rconn.c @@ -76,6 +76,7 @@ struct rconn { time_t last_connected; unsigned int packets_sent; unsigned int seqno; + int last_error; /* In S_ACTIVE and S_IDLE, probably_admitted reports whether we believe * that the peer has made a (positive) admission control decision on our @@ -177,7 +178,7 @@ rconn_new_from_vconn(const char *name, struct vconn *vconn) struct rconn * rconn_create(int probe_interval, int max_backoff) { - struct rconn *rc = xcalloc(1, sizeof *rc); + struct rconn *rc = xzalloc(sizeof *rc); rc->state = S_VOID; rc->state_entered = time_now(); @@ -343,7 +344,7 @@ reconnect(struct rconn *rc) } else { VLOG_WARN("%s: connection failed (%s)", rc->name, strerror(retval)); rc->backoff_deadline = TIME_MAX; /* Prevent resetting backoff. */ - disconnect(rc, 0); + disconnect(rc, retval); } return retval; } @@ -383,7 +384,7 @@ run_CONNECTING(struct rconn *rc) } else if (timed_out(rc)) { VLOG_INFO("%s: connection timed out", rc->name); rc->backoff_deadline = TIME_MAX; /* Prevent resetting backoff. */ - disconnect(rc, 0); + disconnect(rc, ETIMEDOUT); } } @@ -448,7 +449,7 @@ run_IDLE(struct rconn *rc) VLOG_ERR("%s: no response to inactivity probe after %u " "seconds, disconnecting", rc->name, elapsed_in_this_state(rc)); - disconnect(rc, 0); + disconnect(rc, ETIMEDOUT); } else { do_tx_work(rc); } @@ -461,6 +462,15 @@ void rconn_run(struct rconn *rc) { int old_state; + size_t i; + + if (rc->vconn) { + vconn_run(rc->vconn); + } + for (i = 0; i < rc->n_monitors; i++) { + vconn_run(rc->monitors[i]); + } + do { old_state = rc->state; switch (rc->state) { @@ -478,7 +488,17 @@ rconn_run(struct rconn *rc) void rconn_run_wait(struct rconn *rc) { - unsigned int timeo = timeout(rc); + unsigned int timeo; + size_t i; + + if (rc->vconn) { + vconn_run_wait(rc->vconn); + } + for (i = 0; i < rc->n_monitors; i++) { + vconn_run_wait(rc->monitors[i]); + } + + timeo = timeout(rc); if (timeo != UINT_MAX) { unsigned int expires = sat_add(rc->state_entered, timeo); unsigned int remaining = sat_sub(expires, time_now()); @@ -792,6 +812,22 @@ rconn_get_connection_seqno(const struct rconn *rc) { return rc->seqno; } + +/* Returns a value that explains why 'rc' last disconnected: + * + * - 0 means that the last disconnection was caused by a call to + * rconn_disconnect(), or that 'rc' is new and has not yet completed its + * initial connection or connection attempt. + * + * - EOF means that the connection was closed in the normal way by the peer. + * + * - A positive integer is an errno value that represents the error. + */ +int +rconn_get_last_error(const struct rconn *rc) +{ + return rc->last_error; +} struct rconn_packet_counter * rconn_packet_counter_create(void) @@ -883,10 +919,20 @@ report_error(struct rconn *rc, int error) } } -/* Disconnects 'rc'. */ +/* Disconnects 'rc' and records 'error' as the error that caused 'rc''s last + * disconnection: + * + * - 0 means that this disconnection is due to a request by 'rc''s client, + * not due to any kind of network error. + * + * - EOF means that the connection was closed in the normal way by the peer. + * + * - A positive integer is an errno value that represents the error. + */ static void -disconnect(struct rconn *rc, int error OVS_UNUSED) +disconnect(struct rconn *rc, int error) { + rc->last_error = error; if (rc->reliable) { time_t now = time_now();