Make vconn-tcp log an error when the connection drops mid-packet.
[openvswitch] / switch / controller.c
index 8f06f67ff747a29f9be3e7b2654b18e816030e94..d8152311e90d4975595c9587bebaa976915d1d5f 100644 (file)
@@ -35,7 +35,6 @@
 #include <errno.h>
 #include <string.h>
 #include "buffer.h"
-#include "forward.h"
 #include "poll-loop.h"
 #include "ofp-print.h"
 #include "util.h"
 #define THIS_MODULE VLM_controller_connection
 #include "vlog.h"
 
-void
-controller_init(struct controller_connection *cc,
-                const char *name, bool reliable)
+struct controller_connection {
+    bool reliable;
+    const char *name;
+    struct vconn *vconn;
+    bool connected;
+    struct queue txq;
+    time_t backoff_deadline;
+    int backoff;
+};
+
+struct controller_connection *
+controller_new(const char *name, bool reliable)
 {
+    struct controller_connection *cc = xmalloc(sizeof *cc);
     cc->reliable = reliable;
     cc->name = name;
     cc->vconn = NULL;
     queue_init(&cc->txq);
     cc->backoff_deadline = 0;
     cc->backoff = 0;
+    return cc;
 }
 
 static int
@@ -70,7 +80,7 @@ try_send(struct controller_connection *cc)
 }
 
 void
-controller_run(struct controller_connection *cc, struct datapath *dp)
+controller_run(struct controller_connection *cc)
 {
     if (!cc->vconn) {
         if (time(0) >= cc->backoff_deadline) {
@@ -101,22 +111,6 @@ controller_run(struct controller_connection *cc, struct datapath *dp)
             controller_disconnect(cc, 0);
         }
     } else {
-        int iterations;
-
-        for (iterations = 0; iterations < 50; iterations++) {
-            struct buffer *buffer;
-            int error = vconn_recv(cc->vconn, &buffer);
-            if (!error) {
-                fwd_control_input(dp, buffer->data, buffer->size);
-                buffer_delete(buffer);
-            } else if (error == EAGAIN) {
-                break;
-            } else {
-                controller_disconnect(cc, error);
-                return;
-            }
-        }
-
         while (cc->txq.n > 0) {
             int error = try_send(cc);
             if (error == EAGAIN) {
@@ -125,7 +119,19 @@ controller_run(struct controller_connection *cc, struct datapath *dp)
                 controller_disconnect(cc, error);
                 return;
             }
-        } 
+        }
+    }
+}
+
+void
+controller_run_wait(struct controller_connection *cc) 
+{
+    if (cc->vconn) {
+        if (cc->txq.n) {
+            vconn_wait(cc->vconn, WAIT_SEND);
+        }
+    } else {
+        poll_timer_wait((cc->backoff_deadline - time(0)) * 1000);
     }
 }
 
@@ -162,16 +168,26 @@ controller_disconnect(struct controller_connection *cc, int error)
     cc->backoff_deadline = now + cc->backoff;
 }
 
+struct buffer *
+controller_recv(struct controller_connection *cc)
+{
+    if (cc->vconn && cc->connected) {
+        struct buffer *buffer;
+        int error = vconn_recv(cc->vconn, &buffer);
+        if (!error) {
+            return buffer;
+        } else if (error != EAGAIN) {
+            controller_disconnect(cc, error); 
+        }
+    }
+    return NULL;
+}
+
 void
-controller_wait(struct controller_connection *cc) 
+controller_recv_wait(struct controller_connection *cc) 
 {
     if (cc->vconn) {
         vconn_wait(cc->vconn, WAIT_RECV);
-        if (cc->txq.n) {
-            vconn_wait(cc->vconn, WAIT_SEND);
-        }
-    } else {
-        poll_timer_wait((cc->backoff_deadline - time(0)) * 1000);
     }
 }