Skip to content

Commit

Permalink
Add IOScheduler and IOUring
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Sep 14, 2024
1 parent b3a2ca3 commit d3c5cc4
Show file tree
Hide file tree
Showing 17 changed files with 5,007 additions and 34 deletions.
44 changes: 44 additions & 0 deletions examples/iouring/source/app.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import std.stdio : writeln;
import concurrency;
import concurrency.socket;
import concurrency.io;
import concurrency.operations.whenall;

void main() @safe
{
auto fd = listen("127.0.0.1", 0);
auto io = IOUringContext.construct(256);
auto socket = getSocket();
auto port = fd.getPort();

writeln("Listening on 127.0.0.1:", port);

writeln("Connecting...");
auto client = io.run(
whenAll(
io.accept(fd),
io.connect(socket, "127.0.0.1", port),
)
).syncWait().value[0];


ubyte[4] bufferRead;
ubyte[4] bufferSend;
bufferSend[0..4] = [1,2,3,4];

writeln("Transmitting...");
auto result = io.run(
whenAll(
io.write(socket, bufferSend[]),
io.read(client.fd, bufferRead[]),
)
).syncWait().value[1];


writeln("Closing...");
closeSocket(client.fd);
closeSocket(socket);
closeSocket(fd);

writeln("Got: ", result);
}
Loading

0 comments on commit d3c5cc4

Please sign in to comment.