X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Frconn.c;h=771b3a30400812ccfeb9c23217be0c5332cf86b2;hb=67a4917b07031b387beafaedce413b4207214059;hp=a27e4321d261bea5d95f40f0a1e3fe05b46a6a14;hpb=39fb08818bbd9c438dbf23caa89937c663451b5a;p=openvswitch diff --git a/lib/rconn.c b/lib/rconn.c index a27e4321..771b3a30 100644 --- a/lib/rconn.c +++ b/lib/rconn.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -313,13 +313,13 @@ rconn_destroy(struct rconn *rc) } static unsigned int -timeout_VOID(const struct rconn *rc UNUSED) +timeout_VOID(const struct rconn *rc OVS_UNUSED) { return UINT_MAX; } static void -run_VOID(struct rconn *rc UNUSED) +run_VOID(struct rconn *rc OVS_UNUSED) { /* Nothing to do. */ } @@ -499,7 +499,7 @@ rconn_recv(struct rconn *rc) int error = vconn_recv(rc->vconn, &buffer); if (!error) { copy_to_monitor(rc, buffer); - if (is_admitted_msg(buffer) + if (rc->probably_admitted || is_admitted_msg(buffer) || time_now() - rc->last_connected >= 30) { rc->probably_admitted = true; rc->last_admitted = time_now(); @@ -547,7 +547,7 @@ rconn_send(struct rconn *rc, struct ofpbuf *b, if (rconn_is_connected(rc)) { COVERAGE_INC(rconn_queued); copy_to_monitor(rc, b); - b->private = counter; + b->private_p = counter; if (counter) { rconn_packet_counter_inc(counter); } @@ -637,15 +637,22 @@ rconn_is_connected(const struct rconn *rconn) return is_connected_state(rconn->state); } -/* Returns 0 if 'rconn' is connected. Otherwise, if 'rconn' is in a "failure - * mode" (that is, it is not connected), returns the number of seconds that it - * has been in failure mode, ignoring any times that it connected but the - * controller's admission control policy caused it to be quickly - * disconnected. */ +/* Returns true if 'rconn' is connected and thought to have been accepted by + * the peer's admission-control policy. */ +bool +rconn_is_admitted(const struct rconn *rconn) +{ + return (rconn_is_connected(rconn) + && rconn->last_admitted >= rconn->last_connected); +} + +/* Returns 0 if 'rconn' is currently connected and considered to have been + * accepted by the peer's admission-control policy, otherwise the number of + * seconds since 'rconn' was last in such a state. */ int rconn_failure_duration(const struct rconn *rconn) { - return rconn_is_connected(rconn) ? 0 : time_now() - rconn->last_admitted; + return rconn_is_admitted(rconn) ? 0 : time_now() - rconn->last_admitted; } /* Returns the IP address of the peer, or 0 if the peer's IP address is not @@ -838,7 +845,7 @@ try_send(struct rconn *rc) { int retval = 0; struct ofpbuf *next = rc->txq.head->next; - struct rconn_packet_counter *counter = rc->txq.head->private; + struct rconn_packet_counter *counter = rc->txq.head->private_p; retval = vconn_send(rc->vconn, rc->txq.head); if (retval) { if (retval != EAGAIN) { @@ -907,7 +914,7 @@ flush_queue(struct rconn *rc) } while (rc->txq.n > 0) { struct ofpbuf *b = queue_pop_head(&rc->txq); - struct rconn_packet_counter *counter = b->private; + struct rconn_packet_counter *counter = b->private_p; if (counter) { rconn_packet_counter_dec(counter); }