Adjust high level wrapper and test.

This commit is contained in:
Sönke Ludwig 2017-01-15 21:59:15 +01:00
parent 2ca7932a66
commit 672e1c951d
2 changed files with 5 additions and 5 deletions

View file

@ -93,9 +93,9 @@ struct StreamListenSocket {
void waitForConnections(alias callback)(ref StreamListenSocket socket) void waitForConnections(alias callback)(ref StreamListenSocket socket)
{ {
void cb(StreamListenSocketFD, StreamSocketFD sock) @safe nothrow { void cb(StreamListenSocketFD, StreamSocketFD sock, scope RefAddress addr) @safe nothrow {
auto ss = StreamSocket(sock); auto ss = StreamSocket(sock);
callback(ss); callback(ss, addr);
} }
eventDriver.sockets.waitForConnections(socket.m_fd, &cb); eventDriver.sockets.waitForConnections(socket.m_fd, &cb);
} }
@ -116,14 +116,14 @@ struct DatagramSocket {
} }
void receive(alias callback)(ref DatagramSocket socket, ubyte[] buffer, IOMode mode) { void receive(alias callback)(ref DatagramSocket socket, ubyte[] buffer, IOMode mode) {
void cb(DatagramSocketFD fd, IOStatus status, size_t bytes_written, scope Address address) @safe nothrow { void cb(DatagramSocketFD fd, IOStatus status, size_t bytes_written, scope RefAddress address) @safe nothrow {
callback(status, bytes_written, address); callback(status, bytes_written, address);
} }
eventDriver.sockets.receive(socket.m_fd, buffer, mode, &cb); eventDriver.sockets.receive(socket.m_fd, buffer, mode, &cb);
} }
void cancelReceive(ref DatagramSocket socket) { eventDriver.sockets.cancelReceive(socket.m_fd); } void cancelReceive(ref DatagramSocket socket) { eventDriver.sockets.cancelReceive(socket.m_fd); }
void send(alias callback)(ref DatagramSocket socket, const(ubyte)[] buffer, IOMode mode, Address target_address = null) { void send(alias callback)(ref DatagramSocket socket, const(ubyte)[] buffer, IOMode mode, Address target_address = null) {
void cb(DatagramSocketFD fd, IOStatus status, size_t bytes_written, scope Address) @safe nothrow { void cb(DatagramSocketFD fd, IOStatus status, size_t bytes_written, scope RefAddress) @safe nothrow {
callback(status, bytes_written); callback(status, bytes_written);
} }
eventDriver.sockets.send(socket.m_fd, buffer, mode, target_address, &cb); eventDriver.sockets.send(socket.m_fd, buffer, mode, target_address, &cb);

View file

@ -22,7 +22,7 @@ void main()
StreamSocket client; StreamSocket client;
StreamSocket incoming; StreamSocket incoming;
server.waitForConnections!((incoming_) { server.waitForConnections!((incoming_, addr) {
incoming = incoming_; // work around ref counting issue incoming = incoming_; // work around ref counting issue
incoming.read!((status, bts) { incoming.read!((status, bts) {
assert(status == IOStatus.ok); assert(status == IOStatus.ok);