Merge pull request #111 from WebFreak001/fix-110
Make waitForData not assert fail on close fix #110
This commit is contained in:
commit
0d3338a16b
|
@ -569,12 +569,18 @@ mixin(tracer);
|
||||||
alias waiter = Waitable!(IOCallback,
|
alias waiter = Waitable!(IOCallback,
|
||||||
cb => eventDriver.sockets.read(m_socket, m_context.readBuffer.peekDst(), mode, cb),
|
cb => eventDriver.sockets.read(m_socket, m_context.readBuffer.peekDst(), mode, cb),
|
||||||
(cb) { cancelled = true; eventDriver.sockets.cancelRead(m_socket); },
|
(cb) { cancelled = true; eventDriver.sockets.cancelRead(m_socket); },
|
||||||
(sock, st, nb) { assert(sock == m_socket); status = st; nbytes = nb; }
|
(sock, st, nb) {
|
||||||
|
if (m_socket == StreamSocketFD.invalid) {
|
||||||
|
cancelled = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
assert(sock == m_socket); status = st; nbytes = nb;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
asyncAwaitAny!(true, waiter)(timeout);
|
asyncAwaitAny!(true, waiter)(timeout);
|
||||||
|
|
||||||
if (cancelled) return false;
|
if (cancelled || !m_context) return false;
|
||||||
|
|
||||||
logTrace("Socket %s, read %s bytes: %s", m_socket, nbytes, status);
|
logTrace("Socket %s, read %s bytes: %s", m_socket, nbytes, status);
|
||||||
|
|
||||||
|
|
39
tests/issue-110-close-while-waitForData.d
Normal file
39
tests/issue-110-close-while-waitForData.d
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/+ dub.sdl:
|
||||||
|
name "test"
|
||||||
|
dependency "vibe-core" path=".."
|
||||||
|
+/
|
||||||
|
module test;
|
||||||
|
|
||||||
|
import core.time;
|
||||||
|
|
||||||
|
import vibe.core.core;
|
||||||
|
import vibe.core.net;
|
||||||
|
|
||||||
|
ushort port;
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
runTask(&server);
|
||||||
|
runTask(&client);
|
||||||
|
|
||||||
|
runEventLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void server()
|
||||||
|
{
|
||||||
|
auto listener = listenTCP(0, (conn) @safe nothrow {
|
||||||
|
try { sleep(200.msecs); } catch (Exception) {}
|
||||||
|
});
|
||||||
|
port = listener[0].bindAddress.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
void client()
|
||||||
|
{
|
||||||
|
sleep(100.msecs);
|
||||||
|
auto tcp = connectTCP("127.0.0.1", port);
|
||||||
|
runTask({
|
||||||
|
sleep(10.msecs);
|
||||||
|
tcp.close();
|
||||||
|
});
|
||||||
|
assert(!tcp.waitForData());
|
||||||
|
exitEventLoop(true);
|
||||||
|
}
|
Loading…
Reference in a new issue