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
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();
} 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;
}
} 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);
}
}
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);
}
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) {
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());
{
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;
+}
\f
struct rconn_packet_counter *
rconn_packet_counter_create(void)
}
}
-/* 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();