Extend datagram socket API.
Adds .setTargetAddress() and makes .getXAddress() work for datagram sockets, too.
This commit is contained in:
parent
2e5b13ee98
commit
1d330d6330
|
@ -157,10 +157,10 @@ interface EventDriverSockets {
|
|||
ConnectionState getConnectionState(StreamSocketFD sock);
|
||||
|
||||
/// Retrieves the bind address of a socket.
|
||||
bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst);
|
||||
bool getLocalAddress(SocketFD sock, scope RefAddress dst);
|
||||
|
||||
/// Retrieves the address of the connected peer.
|
||||
bool getRemoteAddress(StreamSocketFD sock, scope RefAddress dst);
|
||||
bool getRemoteAddress(SocketFD sock, scope RefAddress dst);
|
||||
|
||||
/// Sets the `TCP_NODELAY` option on a socket
|
||||
void setTCPNoDelay(StreamSocketFD socket, bool enable);
|
||||
|
@ -248,6 +248,10 @@ interface EventDriverSockets {
|
|||
*/
|
||||
DatagramSocketFD adoptDatagramSocket(int socket);
|
||||
|
||||
/** Sets an address to use as the default target address for sent datagrams.
|
||||
*/
|
||||
void setTargetAddress(DatagramSocketFD socket, scope Address target_address);
|
||||
|
||||
/// Sets the `SO_BROADCAST` socket option.
|
||||
bool setBroadcast(DatagramSocketFD socket, bool enable);
|
||||
|
||||
|
|
|
@ -213,7 +213,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
|||
return m_loop.m_fds[sock].streamSocket.state;
|
||||
}
|
||||
|
||||
final override bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst)
|
||||
final override bool getLocalAddress(SocketFD sock, scope RefAddress dst)
|
||||
{
|
||||
socklen_t addr_len = dst.nameLen;
|
||||
if (() @trusted { return getpeername(cast(sock_t)sock, dst.name, &addr_len); } () != 0)
|
||||
|
@ -222,7 +222,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
|||
return true;
|
||||
}
|
||||
|
||||
final override bool getRemoteAddress(StreamSocketFD sock, scope RefAddress dst)
|
||||
final override bool getRemoteAddress(SocketFD sock, scope RefAddress dst)
|
||||
{
|
||||
socklen_t addr_len = dst.nameLen;
|
||||
if (() @trusted { return getsockname(cast(sock_t)sock, dst.name, &addr_len); } () != 0)
|
||||
|
@ -552,6 +552,11 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
|||
return fd;
|
||||
}
|
||||
|
||||
final override void setTargetAddress(DatagramSocketFD socket, scope Address target_address)
|
||||
{
|
||||
() @trusted { connect(cast(sock_t)socket, target_address.name, target_address.nameLen); } ();
|
||||
}
|
||||
|
||||
final override bool setBroadcast(DatagramSocketFD socket, bool enable)
|
||||
{
|
||||
int tmp_broad = enable;
|
||||
|
|
|
@ -35,12 +35,12 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
|||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
override bool getLocalAddress(StreamSocketFD sock, scope RefAddress dst)
|
||||
override bool getLocalAddress(SocketFD sock, scope RefAddress dst)
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
override bool getRemoteAddress(StreamSocketFD sock, scope RefAddress dst)
|
||||
override bool getRemoteAddress(SocketFD sock, scope RefAddress dst)
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue