Fix out of order processing issue with the TCP connection callback.

It could happen that the socket FD got reused before the connection callback was cleared. This in turn could result in the new connection callback to get overwritten with null.
This commit is contained in:
Sönke Ludwig 2017-01-30 10:54:43 +01:00
parent 4703f021ec
commit 956978cc79
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C

View file

@ -43,6 +43,8 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
final override StreamSocketFD connectStream(scope Address address, scope Address bind_address, ConnectCallback on_connect)
{
assert(on_connect !is null);
auto sockfd = createSocket(address.addressFamily, SOCK_STREAM);
if (sockfd == -1) return StreamSocketFD.invalid;
@ -105,8 +107,10 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
m_loop.setNotifyCallback!(EventType.write)(sock, null);
with (m_loop.m_fds[sock].streamSocket) {
state = ConnectionState.connected;
connectCallback(cast(StreamSocketFD)sock, ConnectStatus.connected);
assert(connectCallback !is null);
auto cb = connectCallback;
connectCallback = null;
cb(cast(StreamSocketFD)sock, ConnectStatus.connected);
}
}