Merge pull request #55 from vibe-d/issue_54_accept_state
Fix connection state after accept in the WinAPI driver
This commit is contained in:
commit
cdbd8b58e8
|
@ -55,7 +55,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
return StreamSocketFD.invalid;
|
return StreamSocketFD.invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sock = adoptStreamInternal(fd);
|
auto sock = adoptStreamInternal(fd, ConnectionState.connecting);
|
||||||
|
|
||||||
auto ret = .connect(fd, peer_address.name, peer_address.nameLen);
|
auto ret = .connect(fd, peer_address.name, peer_address.nameLen);
|
||||||
//auto ret = WSAConnect(m_socket, peer_address.name, peer_address.nameLen, null, null, null, null);
|
//auto ret = WSAConnect(m_socket, peer_address.name, peer_address.nameLen, null, null, null, null);
|
||||||
|
@ -70,7 +70,6 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
if (err == WSAEWOULDBLOCK) {
|
if (err == WSAEWOULDBLOCK) {
|
||||||
with (m_sockets[sock].streamSocket) {
|
with (m_sockets[sock].streamSocket) {
|
||||||
connectCallback = on_connect;
|
connectCallback = on_connect;
|
||||||
state = ConnectionState.connecting;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_core.addWaiter();
|
m_core.addWaiter();
|
||||||
|
@ -99,10 +98,10 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
|
|
||||||
override StreamSocketFD adoptStream(int socket)
|
override StreamSocketFD adoptStream(int socket)
|
||||||
{
|
{
|
||||||
return adoptStreamInternal(socket);
|
return adoptStreamInternal(socket, ConnectionState.connected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StreamSocketFD adoptStreamInternal(SOCKET socket)
|
private StreamSocketFD adoptStreamInternal(SOCKET socket, ConnectionState state)
|
||||||
{
|
{
|
||||||
auto fd = StreamSocketFD(socket);
|
auto fd = StreamSocketFD(socket);
|
||||||
if (m_sockets[fd].common.refCount) // FD already in use?
|
if (m_sockets[fd].common.refCount) // FD already in use?
|
||||||
|
@ -123,6 +122,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
initSocketSlot(fd);
|
initSocketSlot(fd);
|
||||||
with (m_sockets[socket]) {
|
with (m_sockets[socket]) {
|
||||||
specific = StreamSocketSlot.init;
|
specific = StreamSocketSlot.init;
|
||||||
|
streamSocket.state = state;
|
||||||
setupOverlapped(streamSocket.write.overlapped);
|
setupOverlapped(streamSocket.write.overlapped);
|
||||||
setupOverlapped(streamSocket.read.overlapped);
|
setupOverlapped(streamSocket.read.overlapped);
|
||||||
}
|
}
|
||||||
|
@ -833,7 +833,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
socklen_t addr_len = addr.sizeof;
|
socklen_t addr_len = addr.sizeof;
|
||||||
auto clientsockfd = () @trusted { return WSAAccept(sock, cast(sockaddr*)&addr, &addr_len, null, 0); } ();
|
auto clientsockfd = () @trusted { return WSAAccept(sock, cast(sockaddr*)&addr, &addr_len, null, 0); } ();
|
||||||
if (clientsockfd == INVALID_SOCKET) return 0;
|
if (clientsockfd == INVALID_SOCKET) return 0;
|
||||||
auto clientsock = driver.adoptStreamInternal(clientsockfd);
|
auto clientsock = driver.adoptStreamInternal(clientsockfd, ConnectionState.connected);
|
||||||
scope RefAddress addrc = new RefAddress(() @trusted { return cast(sockaddr*)&addr; } (), addr_len);
|
scope RefAddress addrc = new RefAddress(() @trusted { return cast(sockaddr*)&addr; } (), addr_len);
|
||||||
slot.streamListen.acceptCallback(cast(StreamListenSocketFD)sock, clientsock, addrc);
|
slot.streamListen.acceptCallback(cast(StreamListenSocketFD)sock, clientsock, addrc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ void main()
|
||||||
|
|
||||||
server.waitForConnections!((incoming_, addr) {
|
server.waitForConnections!((incoming_, addr) {
|
||||||
incoming = incoming_; // work around ref counting issue
|
incoming = incoming_; // work around ref counting issue
|
||||||
|
assert(incoming.state == ConnectionState.connected);
|
||||||
print("Got incoming, reading data");
|
print("Got incoming, reading data");
|
||||||
incoming.read!((status, bts) {
|
incoming.read!((status, bts) {
|
||||||
print("Got data");
|
print("Got data");
|
||||||
|
@ -67,6 +68,7 @@ void main()
|
||||||
connectStream!((sock, status) {
|
connectStream!((sock, status) {
|
||||||
client = sock;
|
client = sock;
|
||||||
assert(status == ConnectStatus.connected);
|
assert(status == ConnectStatus.connected);
|
||||||
|
assert(sock.state == ConnectionState.connected);
|
||||||
print("Initial write");
|
print("Initial write");
|
||||||
client.write!((wstatus, bytes) {
|
client.write!((wstatus, bytes) {
|
||||||
print("Initial write done");
|
print("Initial write done");
|
||||||
|
|
Loading…
Reference in a new issue