Remove stack optimizations for DNS lookups and streamline send() signature.

This commit is contained in:
Sönke Ludwig 2016-10-25 00:12:13 +02:00
parent 39afb2ad21
commit 88600c5e21
2 changed files with 9 additions and 8 deletions

View file

@ -93,7 +93,7 @@ interface EventDriverSockets {
DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address); DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address);
void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish); void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish);
void cancelReceive(DatagramSocketFD socket); void cancelReceive(DatagramSocketFD socket);
void send(DatagramSocketFD socket, const(ubyte)[] buffer, IOMode mode, DatagramIOCallback on_send_finish, Address target_address); void send(DatagramSocketFD socket, const(ubyte)[] buffer, IOMode mode, Address target_address, DatagramIOCallback on_send_finish);
void cancelSend(DatagramSocketFD socket); void cancelSend(DatagramSocketFD socket);
/** Increments the reference count of the given resource. /** Increments the reference count of the given resource.
@ -234,8 +234,8 @@ interface EventDriverWatchers {
alias ConnectCallback = void delegate(StreamSocketFD, ConnectStatus); alias ConnectCallback = void delegate(StreamSocketFD, ConnectStatus);
alias AcceptCallback = void delegate(StreamListenSocketFD, StreamSocketFD); alias AcceptCallback = void delegate(StreamListenSocketFD, StreamSocketFD);
alias IOCallback = void delegate(StreamSocketFD, IOStatus, size_t); alias IOCallback = void delegate(StreamSocketFD, IOStatus, size_t);
alias DatagramIOCallback = void delegate(DatagramSocketFD, IOStatus, size_t, scope Address); alias DatagramIOCallback = void delegate(DatagramSocketFD, IOStatus, size_t, /*scope*/ Address);
alias DNSLookupCallback = void delegate(DNSLookupID, DNSStatus, scope Address[]); alias DNSLookupCallback = void delegate(DNSLookupID, DNSStatus, /*scope*/ Address[]);
alias FileIOCallback = void delegate(FileFD, IOStatus, size_t); alias FileIOCallback = void delegate(FileFD, IOStatus, size_t);
alias EventCallback = void delegate(EventID); alias EventCallback = void delegate(EventID);
alias SignalCallback = void delegate(SignalListenID, SignalStatus, int); alias SignalCallback = void delegate(SignalListenID, SignalStatus, int);

View file

@ -665,7 +665,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
() @trusted { return cast(DatagramIOCallback)slot.readCallback; } ()(socket, IOStatus.ok, ret, src_addr); () @trusted { return cast(DatagramIOCallback)slot.readCallback; } ()(socket, IOStatus.ok, ret, src_addr);
} }
void send(DatagramSocketFD socket, const(ubyte)[] buffer, IOMode mode, DatagramIOCallback on_send_finish, Address target_address = null) void send(DatagramSocketFD socket, const(ubyte)[] buffer, IOMode mode, Address target_address, DatagramIOCallback on_send_finish)
{ {
assert(mode != IOMode.all, "Only IOMode.immediate and IOMode.once allowed for datagram sockets."); assert(mode != IOMode.all, "Only IOMode.immediate and IOMode.once allowed for datagram sockets.");
@ -924,7 +924,7 @@ final class EventDriverDNS_GAIA(Events : EventDriverEvents, Signals : EventDrive
@safe nothrow @safe nothrow
{ {
assert(status == SignalStatus.ok); assert(status == SignalStatus.ok);
foreach (i, l; m_lookups) { foreach (i, ref l; m_lookups) {
if (!l.callback) continue; if (!l.callback) continue;
auto err = gai_error(&l.ctx); auto err = gai_error(&l.ctx);
if (err == EAI_INPROGRESS) continue; if (err == EAI_INPROGRESS) continue;
@ -989,11 +989,12 @@ private void passToDNSCallback(DNSLookupID id, scope DNSLookupCallback cb, DNSSt
scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(),
scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr() scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr(), scoped!RefAddr()
]; ];
Address[16] addrs; //Address[16] addrs;
auto addrs = new Address[16]; // FIXME: avoid heap allocation
auto ai = ai_orig; auto ai = ai_orig;
size_t addr_count = 0; size_t addr_count = 0;
while (ai !is null && addr_count < addrs.length) { while (ai !is null && addr_count < addrs.length) {
RefAddr ua = addrs_prealloc[addr_count]; RefAddr ua = new RefAddr;//addrs_prealloc[addr_count]; // FIXME: avoid heap allocation
ua.sa = ai.ai_addr; ua.sa = ai.ai_addr;
ua.len = ai.ai_addrlen; ua.len = ai.ai_addrlen;
addrs[addr_count] = ua; addrs[addr_count] = ua;
@ -1153,12 +1154,12 @@ final class SignalFDEventDriverSignals(Loop : PosixEventLoop) : EventDriverSigna
private void onSignal(FD fd) private void onSignal(FD fd)
{ {
SignalListenID lid = cast(SignalListenID)fd; SignalListenID lid = cast(SignalListenID)fd;
auto cb = m_loop.m_fds[fd].signal.callback;
signalfd_siginfo nfo; signalfd_siginfo nfo;
do { do {
auto ret = () @trusted { return read(fd, &nfo, nfo.sizeof); } (); auto ret = () @trusted { return read(fd, &nfo, nfo.sizeof); } ();
if (ret == -1 && errno == EAGAIN) if (ret == -1 && errno == EAGAIN)
break; break;
auto cb = m_loop.m_fds[fd].signal.callback;
if (ret != nfo.sizeof) { if (ret != nfo.sizeof) {
cb(lid, SignalStatus.error, -1); cb(lid, SignalStatus.error, -1);
return; return;