-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testscript.d
executable file
·60 lines (48 loc) · 1.32 KB
/
testscript.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env dub
/+ dub.sdl:
name "rockhopper-testing-script"
dependency "rockhopper" path="."
dependency "eventcore" version="~>0.9.29"
+/
module testscript;
// this script is used for testing rockhopper, and can either be ran with `./testscript.d`, or `dub testscript.d`
import std.stdio;
import std.datetime : dur, MonoTime;
import std.conv : to;
import std.string : representation, assumeUTF;
import std.socket : parseAddress;
import eventcore.driver : ConnectStatus, IOStatus, IOMode;
import rockhopper.core;
import rockhopper.rhapi;
import eventcore.core : eventDriver;
import core.thread.osthread : Thread;
mixin rhMain!({
StreamListen sl;
sl.addr = parseAddress("::1", 8080);
sl.registerListen();
while (true)
{
writeln("waiting for conn...");
// listen for incoming tcp connections
auto stream = sl.wait();
writeln("new connection accepted!");
spawn({
// just clone this to be safe.
auto s = stream[0];
while (true)
{
writeln("in sleep loop! fd: ", s);
sleep(dur!"msecs"(300));
writeln("sleep returned.");
auto res = streamWrite(s, "hi!\n".representation);
// HELP CODE EXECUTION NEVER GETS TO THIS COMMENT HERE, WHY IS MY REACTOR BROKEN?
writeln("write returned");
if (res.status != IOStatus.ok)
{
writeln("err: ", res.status);
break;
}
}
});
}
});