// 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;
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;
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;
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
// 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);
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>;