Make rconn_disconnect() a no-op if already disconnected.
authorBen Pfaff <blp@nicira.com>
Wed, 8 Oct 2008 21:24:18 +0000 (14:24 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 9 Oct 2008 22:53:05 +0000 (15:53 -0700)
lib/rconn.c

index 81954955e65fc875e75cddb5b3f7a401772b4f1d..e5f377b9670fbe9ed39703db7c9c06c8cbc65af8 100644 (file)
@@ -227,18 +227,20 @@ rconn_connect_unreliably(struct rconn *rc,
 void
 rconn_disconnect(struct rconn *rc)
 {
-    if (rc->vconn) {
-        vconn_close(rc->vconn);
-        rc->vconn = NULL;
-    }
-    free(rc->name);
-    rc->name = xstrdup("void");
-    rc->reliable = false;
+    if (rc->state != S_VOID) {
+        if (rc->vconn) {
+            vconn_close(rc->vconn);
+            rc->vconn = NULL;
+        }
+        free(rc->name);
+        rc->name = xstrdup("void");
+        rc->reliable = false;
 
-    rc->backoff = 0;
-    rc->backoff_deadline = TIME_MIN;
+        rc->backoff = 0;
+        rc->backoff_deadline = TIME_MIN;
 
-    state_transition(rc, S_VOID);
+        state_transition(rc, S_VOID);
+    }
 }
 
 /* Disconnects 'rc' and frees the underlying storage. */