Skip to content

Commit 373a813

Browse files
committed
Add IOScheduler and IOUring
1 parent 9b3c09b commit 373a813

File tree

17 files changed

+5041
-34
lines changed

17 files changed

+5041
-34
lines changed

examples/iouring/source/app.d

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import std.stdio : writeln;
2+
import concurrency;
3+
import concurrency.socket;
4+
import concurrency.io;
5+
import concurrency.operations.whenall;
6+
7+
void main() @safe
8+
{
9+
auto fd = listen("127.0.0.1", 0);
10+
auto io = IOUringContext.construct(256);
11+
auto socket = getSocket();
12+
auto port = fd.getPort();
13+
14+
writeln("Listening on 127.0.0.1:", port);
15+
16+
writeln("Connecting...");
17+
auto client = io.run(
18+
whenAll(
19+
io.accept(fd),
20+
io.connect(socket, "127.0.0.1", port),
21+
)
22+
).syncWait().value[0];
23+
24+
25+
ubyte[4] bufferRead;
26+
ubyte[4] bufferSend;
27+
bufferSend[0..4] = [1,2,3,4];
28+
29+
writeln("Transmitting...");
30+
auto result = io.run(
31+
whenAll(
32+
io.write(socket, bufferSend[]),
33+
io.read(client.fd, bufferRead[]),
34+
)
35+
).syncWait().value[1];
36+
37+
38+
writeln("Closing...");
39+
closeSocket(client.fd);
40+
closeSocket(socket);
41+
closeSocket(fd);
42+
43+
writeln("Got: ", result);
44+
}

0 commit comments

Comments
 (0)