2017-02-16 23:55:16 +00:00
|
|
|
/+ dub.sdl:
|
|
|
|
name "tests"
|
|
|
|
description "TCP disconnect task issue"
|
|
|
|
dependency "vibe-core" path="../"
|
|
|
|
+/
|
|
|
|
module test;
|
|
|
|
|
|
|
|
import vibe.core.core;
|
|
|
|
import vibe.core.net;
|
|
|
|
import core.time : msecs;
|
|
|
|
|
2020-03-15 13:01:18 +00:00
|
|
|
void main()
|
2017-02-16 23:55:16 +00:00
|
|
|
{
|
2020-03-15 13:01:18 +00:00
|
|
|
auto l = listenTCP(0, (conn) {
|
2017-02-16 23:55:16 +00:00
|
|
|
auto td = runTask!TCPConnection((conn) {
|
|
|
|
ubyte [3] buf;
|
|
|
|
try {
|
|
|
|
conn.read(buf);
|
|
|
|
assert(false, "Expected read() to throw an exception.");
|
|
|
|
} catch (Exception) {} // expected
|
|
|
|
}, conn);
|
|
|
|
sleep(10.msecs);
|
|
|
|
conn.close();
|
2020-03-15 13:01:18 +00:00
|
|
|
}, "127.0.0.1");
|
2017-02-16 23:55:16 +00:00
|
|
|
|
|
|
|
runTask({
|
|
|
|
try {
|
2020-03-15 13:01:18 +00:00
|
|
|
auto conn = connectTCP("127.0.0.1", l.bindAddress.port);
|
2017-02-16 23:55:16 +00:00
|
|
|
conn.write("a");
|
|
|
|
conn.close();
|
|
|
|
} catch (Exception e) assert(false, e.msg);
|
|
|
|
|
|
|
|
try {
|
2020-03-15 13:01:18 +00:00
|
|
|
auto conn = connectTCP("127.0.0.1", l.bindAddress.port);
|
2017-02-16 23:55:16 +00:00
|
|
|
conn.close();
|
|
|
|
} catch (Exception e) assert(false, e.msg);
|
|
|
|
|
|
|
|
sleep(50.msecs);
|
|
|
|
exitEventLoop();
|
|
|
|
});
|
2020-03-15 13:01:18 +00:00
|
|
|
|
|
|
|
runApplication();
|
|
|
|
|
|
|
|
l.stopListening();
|
2017-02-16 23:55:16 +00:00
|
|
|
}
|