Control protocol cleanups.
authorDavin McCall <davmac@davmac.org>
Mon, 23 Nov 2015 08:29:05 +0000 (08:29 +0000)
committerDavin McCall <davmac@davmac.org>
Mon, 23 Nov 2015 08:29:05 +0000 (08:29 +0000)
control-cmds.h
control.cc
control.h

index f948060846c86c1c3963276dd056105d8eaede36..f0d2e7605d541d2c9079997134b248efe43a7150 100644 (file)
@@ -14,7 +14,7 @@ constexpr static int DINIT_CP_ROLLBACKALL = 2;
 
 // Reply: ACK/NAK to request
 constexpr static int DINIT_RP_ACK = 50;
-//constexpr static int DINIT_RP_NAK = 51;
+constexpr static int DINIT_RP_NAK = 51;
 
 // Request was bad (connection will be closed)
 constexpr static int DINIT_RP_BADREQ = 52;
index df992fa7f63ef3635032cb20efb3a61b411eb30f..fd1c366f4aaff8a63d0520f764ade701d91ad3b1 100644 (file)
@@ -18,7 +18,8 @@ void ControlConn::processPacket()
         
         uint16_t svcSize;
         memcpy(&svcSize, iobuf + 1, 2);
-        if (svcSize <= 0) {
+        chklen = svcSize + 3;
+        if (svcSize <= 0 || chklen > 1024) {
             // Queue error response mark connection bad
             char badreqRep[] = { DINIT_RP_BADREQ };
             if (! queuePacket(badreqRep, 1)) return;
@@ -27,15 +28,6 @@ void ControlConn::processPacket()
             return;
         }
         
-        chklen = svcSize + 3;
-        if (chklen > 1024) {
-            // We can't have a service name this long
-            // TODO error response
-            bad_conn_close = true;
-            ev_io_set(&iob, iob.fd, EV_WRITE);
-            return;
-        }
-        
         if (bufidx < chklen) {
             // packet not complete yet; read more
             return;
@@ -78,7 +70,8 @@ void ControlConn::processPacket()
             if (! queuePacket(ackBuf, 1)) return;
         }
         else {
-            // TODO send NAK
+            char nakBuf[] = { DINIT_RP_NAK };
+            if (! queuePacket(nakBuf, 1)) return;
         }
         
         // Clear the packet from the buffer
index 845f3c7cab38b0d8edec9af917764089539152b4..42ba5a7e3fc289cdf6aee3751d08fbc4cdeda129 100644 (file)
--- a/control.h
+++ b/control.h
@@ -11,6 +11,8 @@
 
 // Control connection for dinit
 
+// TODO: Use the input buffer as a circular buffer, instead of chomping data from
+// the front using a data move.
 
 // forward-declaration of callback:
 static void control_conn_cb(struct ev_loop * loop, ev_io * w, int revents);
@@ -43,7 +45,6 @@ class ControlConn
     int bufidx;
     
     bool bad_conn_close; // close when finished output?
-    //bool bad_conn_wrerr; // write error has occurred
     bool oom_close;      // send final 'out of memory' indicator
     
     template <typename T> using list = std::list<T>;