From 175368b3346151fd5e1808bc6ba91df68baf2ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Tue, 29 Nov 2016 11:58:46 +0100 Subject: [PATCH] Fix erroneously disabling some socket events in the Posix driver. --- source/eventcore/drivers/posix.d | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/source/eventcore/drivers/posix.d b/source/eventcore/drivers/posix.d index 09a0c6d..71415be 100644 --- a/source/eventcore/drivers/posix.d +++ b/source/eventcore/drivers/posix.d @@ -240,7 +240,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets connectCallback = on_connect; state = ConnectionState.connecting; } - m_loop.startNotify!(EventType.write)(sock, &onConnect); + m_loop.setNotifyCallback!(EventType.write)(sock, &onConnect); } else { m_loop.clearFD(sock); m_loop.unregisterFD(sock); @@ -311,7 +311,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets log("wait for conn"); m_loop.registerFD(sock, EventMask.read); m_loop.m_fds[sock].streamListen.acceptCallback = on_accept; - m_loop.startNotify!(EventType.read)(sock, &onAccept); + m_loop.setNotifyCallback!(EventType.read)(sock, &onAccept); onAccept(sock); } @@ -383,6 +383,10 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets } } + // NOTE: since we know that not all data was read from the stream + // socket, the next call to recv is guaranteed to return EGAIN + // and we can avoid that call. + with (m_loop.m_fds[socket].streamSocket) { readCallback = on_read_finish; readMode = mode; @@ -479,6 +483,10 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets } } + // NOTE: since we know that not all data was writtem to the stream + // socket, the next call to send is guaranteed to return EGAIN + // and we can avoid that call. + with (m_loop.m_fds[socket].streamSocket) { writeCallback = on_write_finish; writeMode = mode; @@ -1040,7 +1048,7 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop) : EventDriverEvents { m_loop.initFD(id); m_loop.m_fds[id].specific = EventSlot(new ConsumableQueue!EventCallback); // FIXME: avoid dynamic memory allocation m_loop.registerFD(id, EventMask.read); - m_loop.startNotify!(EventType.read)(id, &onEvent); + m_loop.setNotifyCallback!(EventType.read)(id, &onEvent); return id; } else assert(false, "OS not supported!"); } @@ -1390,22 +1398,6 @@ package class PosixEventLoop { del(cast(FD)i); } - package void startNotify(EventType evt)(FD fd, FDSlotCallback callback) - { - //log("start notify %s %s", evt, fd); - //assert(m_fds[fd].callback[evt] is null, "Waiting for event which is already being waited for."); - if (callback) setNotifyCallback!evt(fd, callback); - updateFD(fd, m_fds[fd.value].common.eventMask); - } - - package void stopNotify(EventType evt)(FD fd) - { - //log("stop notify %s %s", evt, fd); - //ssert(m_fds[fd].callback[evt] !is null, "Stopping waiting for event which is not being waited for."); - if (m_fds[fd].callback) setNotifyCallback!evt(fd, null); - updateFD(fd, m_fds[fd.value].common.eventMask); - } - package void setNotifyCallback(EventType evt)(FD fd, FDSlotCallback callback) { assert((callback !is null) != (m_fds[fd.value].common.callback[evt] !is null),