Make ofp_error() preserve the value of errno.
[sliver-openvswitch.git] / lib / rconn.c
index c29e69a..8195495 100644 (file)
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
-#include "buffer.h"
+#include "ofpbuf.h"
 #include "openflow.h"
 #include "poll-loop.h"
-#include "ofp-print.h"
 #include "sat-math.h"
 #include "timeval.h"
 #include "util.h"
@@ -84,7 +83,7 @@ struct rconn {
     char *name;
     bool reliable;
 
-    struct queue txq;
+    struct ofp_queue txq;
 
     int backoff;
     int max_backoff;
@@ -131,7 +130,7 @@ static int reconnect(struct rconn *);
 static void disconnect(struct rconn *, int error);
 static void flush_queue(struct rconn *);
 static void question_connectivity(struct rconn *);
-static void copy_to_monitor(struct rconn *, const struct buffer *);
+static void copy_to_monitor(struct rconn *, const struct ofpbuf *);
 
 /* Creates a new rconn, connects it (reliably) to 'name', and returns it. */
 struct rconn *
@@ -280,6 +279,7 @@ reconnect(struct rconn *rc)
         state_transition(rc, S_CONNECTING);
     } else {
         VLOG_WARN("%s: connection failed (%s)", rc->name, strerror(retval));
+        rc->backoff_deadline = TIME_MAX; /* Prevent resetting backoff. */
         disconnect(rc, 0);
     }
     return retval;
@@ -425,12 +425,12 @@ rconn_run_wait(struct rconn *rc)
 
 /* Attempts to receive a packet from 'rc'.  If successful, returns the packet;
  * otherwise, returns a null pointer.  The caller is responsible for freeing
- * the packet (with buffer_delete()). */
-struct buffer *
+ * the packet (with ofpbuf_delete()). */
+struct ofpbuf *
 rconn_recv(struct rconn *rc)
 {
     if (rc->state & (S_ACTIVE | S_IDLE)) {
-        struct buffer *buffer;
+        struct ofpbuf *buffer;
         int error = vconn_recv(rc->vconn, &buffer);
         if (!error) {
             copy_to_monitor(rc, buffer);
@@ -471,7 +471,7 @@ rconn_recv_wait(struct rconn *rc)
  * takes care of sending if you call rconn_run(), which will have the side
  * effect of waking up poll_block(). */
 int
-rconn_send(struct rconn *rc, struct buffer *b, int *n_queued)
+rconn_send(struct rconn *rc, struct ofpbuf *b, int *n_queued)
 {
     if (rconn_is_connected(rc)) {
         copy_to_monitor(rc, b);
@@ -502,13 +502,13 @@ rconn_send(struct rconn *rc, struct buffer *b, int *n_queued)
  * takes care of sending if you call rconn_run(), which will have the side
  * effect of waking up poll_block(). */
 int
-rconn_send_with_limit(struct rconn *rc, struct buffer *b,
+rconn_send_with_limit(struct rconn *rc, struct ofpbuf *b,
                       int *n_queued, int queue_limit)
 {
     int retval;
     retval = *n_queued >= queue_limit ? EAGAIN : rconn_send(rc, b, n_queued);
     if (retval) {
-        buffer_delete(b);
+        ofpbuf_delete(b);
     }
     return retval;
 }
@@ -666,7 +666,7 @@ static int
 try_send(struct rconn *rc)
 {
     int retval = 0;
-    struct buffer *next = rc->txq.head->next;
+    struct ofpbuf *next = rc->txq.head->next;
     int *n_queued = rc->txq.head->private;
     retval = vconn_send(rc->vconn, rc->txq.head);
     if (retval) {
@@ -734,12 +734,12 @@ flush_queue(struct rconn *rc)
         return;
     }
     while (rc->txq.n > 0) {
-        struct buffer *b = queue_pop_head(&rc->txq);
+        struct ofpbuf *b = queue_pop_head(&rc->txq);
         int *n_queued = b->private;
         if (n_queued) {
             --*n_queued;
         }
-        buffer_delete(b);
+        ofpbuf_delete(b);
     }
     poll_immediate_wake();
 }
@@ -790,9 +790,9 @@ question_connectivity(struct rconn *rc)
 }
 
 static void
-copy_to_monitor(struct rconn *rc, const struct buffer *b)
+copy_to_monitor(struct rconn *rc, const struct ofpbuf *b)
 {
-    struct buffer *clone = NULL;
+    struct ofpbuf *clone = NULL;
     int retval;
     size_t i;
 
@@ -800,7 +800,7 @@ copy_to_monitor(struct rconn *rc, const struct buffer *b)
         struct vconn *vconn = rc->monitors[i];
 
         if (!clone) {
-            clone = buffer_clone(b);
+            clone = ofpbuf_clone(b);
         }
         retval = vconn_send(vconn, clone);
         if (!retval) {
@@ -814,5 +814,5 @@ copy_to_monitor(struct rconn *rc, const struct buffer *b)
         }
         i++;
     }
-    buffer_delete(clone);
+    ofpbuf_delete(clone);
 }