Add EventDriverSockets.getRemoteAddress.

This commit is contained in:
Sönke Ludwig 2017-03-10 20:25:28 +01:00
parent a25b49228f
commit 2e5b13ee98
No known key found for this signature in database
GPG key ID: D95E8DB493EE314C
3 changed files with 18 additions and 2 deletions

View file

@ -159,6 +159,9 @@ interface EventDriverSockets {
/// Retrieves the bind address of a socket. /// Retrieves the bind address of a socket.
bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst); bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst);
/// Retrieves the address of the connected peer.
bool getRemoteAddress(StreamSocketFD sock, scope RefAddress dst);
/// Sets the `TCP_NODELAY` option on a socket /// Sets the `TCP_NODELAY` option on a socket
void setTCPNoDelay(StreamSocketFD socket, bool enable); void setTCPNoDelay(StreamSocketFD socket, bool enable);

View file

@ -213,7 +213,16 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
return m_loop.m_fds[sock].streamSocket.state; return m_loop.m_fds[sock].streamSocket.state;
} }
bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst) final override bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst)
{
socklen_t addr_len = dst.nameLen;
if (() @trusted { return getpeername(cast(sock_t)sock, dst.name, &addr_len); } () != 0)
return false;
dst.cap(addr_len);
return true;
}
final override bool getRemoteAddress(StreamSocketFD sock, scope RefAddress dst)
{ {
socklen_t addr_len = dst.nameLen; socklen_t addr_len = dst.nameLen;
if (() @trusted { return getsockname(cast(sock_t)sock, dst.name, &addr_len); } () != 0) if (() @trusted { return getsockname(cast(sock_t)sock, dst.name, &addr_len); } () != 0)
@ -222,7 +231,6 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
return true; return true;
} }
final override void setTCPNoDelay(StreamSocketFD socket, bool enable) final override void setTCPNoDelay(StreamSocketFD socket, bool enable)
{ {
int opt = enable; int opt = enable;

View file

@ -40,6 +40,11 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
assert(false, "TODO!"); assert(false, "TODO!");
} }
override bool getRemoteAddress(StreamSocketFD sock, scope RefAddress dst)
{
assert(false, "TODO!");
}
override void setTCPNoDelay(StreamSocketFD socket, bool enable) override void setTCPNoDelay(StreamSocketFD socket, bool enable)
{ {
assert(false, "TODO!"); assert(false, "TODO!");