Fix PosixEventDriverSockets.shutdown and .getConnectionState.
This commit is contained in:
parent
0cdde3008c
commit
c85d546efd
|
@ -231,12 +231,14 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
|
|
||||||
auto ret = () @trusted { return connect(sock, address.name, address.nameLen); } ();
|
auto ret = () @trusted { return connect(sock, address.name, address.nameLen); } ();
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
m_loop.m_fds[sock].specific.state = ConnectionState.connected;
|
||||||
on_connect(sock, ConnectStatus.connected);
|
on_connect(sock, ConnectStatus.connected);
|
||||||
} else {
|
} else {
|
||||||
auto err = getSocketError();
|
auto err = getSocketError();
|
||||||
if (err == EINPROGRESS) {
|
if (err == EINPROGRESS) {
|
||||||
with (m_loop.m_fds[sock].streamSocket) {
|
with (m_loop.m_fds[sock].streamSocket) {
|
||||||
connectCallback = on_connect;
|
connectCallback = on_connect;
|
||||||
|
state = ConnectionState.connecting;
|
||||||
}
|
}
|
||||||
m_loop.startNotify!(EventType.write)(sock, &onConnect);
|
m_loop.startNotify!(EventType.write)(sock, &onConnect);
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,13 +256,21 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
private void onConnect(FD sock)
|
private void onConnect(FD sock)
|
||||||
{
|
{
|
||||||
m_loop.setNotifyCallback!(EventType.write)(sock, null);
|
m_loop.setNotifyCallback!(EventType.write)(sock, null);
|
||||||
m_loop.m_fds[sock].streamSocket.connectCallback(cast(StreamSocketFD)sock, ConnectStatus.connected);
|
with (m_loop.m_fds[sock].streamSocket) {
|
||||||
|
state = ConnectionState.connected;
|
||||||
|
connectCallback(cast(StreamSocketFD)sock, ConnectStatus.connected);
|
||||||
|
connectCallback = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onConnectError(FD sock)
|
private void onConnectError(FD sock)
|
||||||
{
|
{
|
||||||
// FIXME: determine the correct kind of error!
|
// FIXME: determine the correct kind of error!
|
||||||
m_loop.m_fds[sock].streamSocket.connectCallback(cast(StreamSocketFD)sock, ConnectStatus.refused);
|
with (m_loop.m_fds[sock].streamSocket) {
|
||||||
|
state = ConnectionState.closed;
|
||||||
|
connectCallback(cast(StreamSocketFD)sock, ConnectStatus.refused);
|
||||||
|
connectCallback = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final override StreamListenSocketFD listenStream(scope Address address, AcceptCallback on_accept)
|
final override StreamListenSocketFD listenStream(scope Address address, AcceptCallback on_accept)
|
||||||
|
@ -327,7 +337,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
|
|
||||||
ConnectionState getConnectionState(StreamSocketFD sock)
|
ConnectionState getConnectionState(StreamSocketFD sock)
|
||||||
{
|
{
|
||||||
assert(false);
|
return m_loop.m_fds[sock].streamSocket.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void setTCPNoDelay(StreamSocketFD socket, bool enable)
|
final override void setTCPNoDelay(StreamSocketFD socket, bool enable)
|
||||||
|
@ -415,6 +425,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
|
slot.state = ConnectionState.passiveClose;
|
||||||
finalize(IOStatus.disconnected);
|
finalize(IOStatus.disconnected);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -578,7 +589,11 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
|
|
||||||
final override void shutdown(StreamSocketFD socket, bool shut_read, bool shut_write)
|
final override void shutdown(StreamSocketFD socket, bool shut_read, bool shut_write)
|
||||||
{
|
{
|
||||||
// TODO!
|
auto st = m_loop.m_fds[socket].streamSocket.state;
|
||||||
|
() @trusted { .shutdown(socket, shut_read ? shut_write ? SHUT_RDWR : SHUT_RD : shut_write ? SHUT_WR : 0); } ();
|
||||||
|
if (st == ConnectionState.passiveClose) shut_read = true;
|
||||||
|
if (st == ConnectionState.activeClose) shut_write = true;
|
||||||
|
m_loop.m_fds[socket].streamSocket.state = shut_read ? shut_write ? ConnectionState.closed : ConnectionState.passiveClose : shut_write ? ConnectionState.activeClose : ConnectionState.connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address)
|
DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address)
|
||||||
|
@ -1454,6 +1469,7 @@ private struct StreamSocketSlot {
|
||||||
IOCallback writeCallback; // FIXME: this type only works for stream sockets
|
IOCallback writeCallback; // FIXME: this type only works for stream sockets
|
||||||
|
|
||||||
ConnectCallback connectCallback;
|
ConnectCallback connectCallback;
|
||||||
|
ConnectionState state;
|
||||||
}
|
}
|
||||||
|
|
||||||
private struct StreamListenSocketSlot {
|
private struct StreamListenSocketSlot {
|
||||||
|
|
Loading…
Reference in a new issue