rconn: Simplify rconn_send() semantics.
authorEthan Jackson <ethan@nicira.com>
Thu, 26 Apr 2012 04:12:18 +0000 (21:12 -0700)
committerEthan Jackson <ethan@nicira.com>
Thu, 26 Apr 2012 07:44:07 +0000 (00:44 -0700)
Before this patch, rconn_send() would delete 'b' on success, and
not on error.  This is confusing and error-prone.  This patch
causes rconn_send() to always delete 'b'.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
lib/learning-switch.c
lib/rconn.c
ofproto/connmgr.c

index 9e36db8..23d26e7 100644 (file)
@@ -178,7 +178,6 @@ lswitch_create(struct rconn *rconn, const struct lswitch_config *cfg)
         if (error) {
             VLOG_INFO_RL(&rl, "%s: failed to queue default flows (%s)",
                          rconn_get_name(rconn), strerror(error));
-            ofpbuf_delete(msg);
         }
     }
 
index 56a7e19..700de11 100644 (file)
@@ -560,9 +560,8 @@ rconn_recv_wait(struct rconn *rc)
     }
 }
 
-/* Sends 'b' on 'rc'.  Returns 0 if successful (in which case 'b' is
- * destroyed), or ENOTCONN if 'rc' is not currently connected (in which case
- * the caller retains ownership of 'b').
+/* Sends 'b' on 'rc'.  Returns 0 if successful, or ENOTCONN if 'rc' is not
+ * currently connected.  Takes ownership of 'b'.
  *
  * If 'counter' is non-null, then 'counter' will be incremented while the
  * packet is in flight, then decremented when it has been sent (or discarded
@@ -595,6 +594,7 @@ rconn_send(struct rconn *rc, struct ofpbuf *b,
         }
         return 0;
     } else {
+        ofpbuf_delete(b);
         return ENOTCONN;
     }
 }
@@ -619,7 +619,6 @@ rconn_send_with_limit(struct rconn *rc, struct ofpbuf *b,
     retval = counter->n >= queue_limit ? EAGAIN : rconn_send(rc, b, counter);
     if (retval) {
         COVERAGE_INC(rconn_overflow);
-        ofpbuf_delete(b);
     }
     return retval;
 }
index 629c14d..281fdd3 100644 (file)
@@ -1225,9 +1225,7 @@ ofconn_send(const struct ofconn *ofconn, struct ofpbuf *msg,
             struct rconn_packet_counter *counter)
 {
     update_openflow_length(msg);
-    if (rconn_send(ofconn->rconn, msg, counter)) {
-        ofpbuf_delete(msg);
-    }
+    rconn_send(ofconn->rconn, msg, counter);
 }
 \f
 /* Sending asynchronous messages. */