My UDPConnection can recv
fine in main, but put inside of a task and it cannot. This behavior is replicated for me in the udp example. All I get is "Sending packet..." and no receiving messages.
On Mon, 03 Feb 2014 17:03:59 GMT, Kelet wrote:
My UDPConnection can
recv
fine in main, but put inside of a task and it cannot. This behavior is replicated for me in the udp example. All I get is "Sending packet..." and no receiving messages.
To clarify, changing the udp example to:
import vibe.appmain;
import vibe.core.core;
import vibe.core.log;
import vibe.core.net;
import core.time;
shared static this()
{
runTask({
auto udp_sender = listenUDP(0);
udp_sender.connect("127.0.0.1", 1234);
while (true) {
sleep(dur!"msecs"(500));
logInfo("Sending packet...");
udp_sender.send(cast(ubyte[])"Hello, World!");
}
});
auto udp_listener = listenUDP(1234);
while (true) {
auto pack = udp_listener.recv();
logInfo("Got packet: %s", cast(string)pack);
}
}
works, whereas the default never receives.
I'm thinking this might be related to when I try to run exitEventLoop()
at the end which yields
core.exception.AssertError@vibe.core.core(119): Assertion failure
Line 119 is
assert(s_eventLoopRunning || shutdown_all_threads);
Which means that the event loop isn't running I think. However, with VibeDefaultMain as in the example, it should be - right? I'm using vibe.d 0.7.19-beta.2 although I've tried many others. Using DMD v2.064.
On Mon, 03 Feb 2014 19:39:47 GMT, Kelet wrote:
On Mon, 03 Feb 2014 17:03:59 GMT, Kelet wrote:
My UDPConnection can
recv
fine in main, but put inside of a task and it cannot. This behavior is replicated for me in the udp example. All I get is "Sending packet..." and no receiving messages.To clarify, changing the udp example to:
import vibe.appmain; import vibe.core.core; import vibe.core.log; import vibe.core.net; import core.time; shared static this() { runTask({ auto udp_sender = listenUDP(0); udp_sender.connect("127.0.0.1", 1234); while (true) { sleep(dur!"msecs"(500)); logInfo("Sending packet..."); udp_sender.send(cast(ubyte[])"Hello, World!"); } }); auto udp_listener = listenUDP(1234); while (true) { auto pack = udp_listener.recv(); logInfo("Got packet: %s", cast(string)pack); } }
works, whereas the default never receives.
This was a bug in the libevent driver. I'm still unsure why the example worked at all when I first implemented it, but at least it's fixed now in d49cfd3.
I'm thinking this might be related to when I try to run
exitEventLoop()
at the end which yieldscore.exception.AssertError@vibe.core.core(119): Assertion failure
Line 119 is
assert(s_eventLoopRunning || shutdown_all_threads);
Which means that the event loop isn't running I think. However, with VibeDefaultMain as in the example, it should be - right? I'm using vibe.d 0.7.19-beta.2 although I've tried many others. Using DMD v2.064.
The event loop isn't started until after static this()
has returned, so calling exitEventLoop
there tries to terminate a loop that hasn't been started yet. A way to achieve this (other than using VibeCustomMain
, of course) is to do runTask({ exitEventLoop(); });
. I've made another fix in 58054cc that makes this approach reliable.
I was pulling my hair out on this last week too but didn't manage to nail it down to what was going wrong. Thanks for reporting/fixing it :)