return queuePacket(ackBuf, 1);
}
-void ControlConn::dataReady() noexcept
+bool ControlConn::dataReady() noexcept
{
int fd = iob.fd;
int buffree = 1024 - bufidx;
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
// TODO log error
delete this;
+ return true;
}
- return;
+ return false;
}
if (r == 0) {
delete this;
- return;
+ return true;
}
bufidx += r;
ev_io_set(&iob, iob.fd, EV_WRITE);
}
- return;
+ return false;
}
void ControlConn::sendData() noexcept
// outgoing packets queued.
void processPacket();
- // Notify that data is ready to be read from the socket.
- void dataReady() noexcept;
+ // Notify that data is ready to be read from the socket. Returns true in cases where the
+ // connection was deleted with potentially pending outgoing packets.
+ bool dataReady() noexcept;
+
void sendData() noexcept;
public:
{
ControlConn *conn = (ControlConn *) w->data;
if (revents & EV_READ) {
- conn->dataReady();
+ if (conn->dataReady()) {
+ // ControlConn was deleted
+ return;
+ }
}
- // TODO issue here: what if above deletes the connection?
if (revents & EV_WRITE) {
conn->sendData();
}