Add EventDriverSockets.setBroadcast.
This commit is contained in:
parent
116940a5a7
commit
8b8169b868
|
@ -65,6 +65,8 @@ interface EventDriverCore {
|
|||
|
||||
/// Low-level user data access. Use `getUserData` instead.
|
||||
protected void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system;
|
||||
/// ditto
|
||||
protected void* rawUserData(DatagramSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system;
|
||||
|
||||
/** Retrieves a reference to a user-defined value associated with a descriptor.
|
||||
*/
|
||||
|
@ -94,6 +96,7 @@ interface EventDriverSockets {
|
|||
void shutdown(StreamSocketFD socket, bool shut_read, bool shut_write);
|
||||
|
||||
DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address);
|
||||
bool setBroadcast(DatagramSocketFD socket, bool enable);
|
||||
void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish);
|
||||
void cancelReceive(DatagramSocketFD socket);
|
||||
void send(DatagramSocketFD socket, const(ubyte)[] buffer, IOMode mode, Address target_address, DatagramIOCallback on_send_finish);
|
||||
|
|
|
@ -75,6 +75,11 @@ final class LibasyncEventDriverCore : EventDriverCore {
|
|||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
protected override void* rawUserData(DatagramSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
}
|
||||
|
||||
final class LibasyncEventDriverSockets : EventDriverSockets {
|
||||
|
@ -149,6 +154,11 @@ final class LibasyncEventDriverSockets : EventDriverSockets {
|
|||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
override bool setBroadcast(DatagramSocketFD socket, bool enable)
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
override void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish)
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
|
|
|
@ -183,6 +183,16 @@ final class PosixEventDriverCore(Loop : PosixEventLoop, Timers : EventDriverTime
|
|||
}
|
||||
|
||||
final protected override void* rawUserData(StreamSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy)
|
||||
@system {
|
||||
return rawUserDataImpl(descriptor, size, initialize, destroy);
|
||||
}
|
||||
|
||||
final protected override void* rawUserData(DatagramSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy)
|
||||
@system {
|
||||
return rawUserDataImpl(descriptor, size, initialize, destroy);
|
||||
}
|
||||
|
||||
private void* rawUserDataImpl(FD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy)
|
||||
@system {
|
||||
FDSlot* fds = &m_loop.m_fds[descriptor].common;
|
||||
assert(fds.userDataDestructor is null || fds.userDataDestructor is destroy,
|
||||
|
@ -624,7 +634,7 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
|||
m_loop.m_fds[socket].streamSocket.state = shut_read ? shut_write ? ConnectionState.closed : ConnectionState.passiveClose : shut_write ? ConnectionState.activeClose : ConnectionState.connected;
|
||||
}
|
||||
|
||||
DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address)
|
||||
final override DatagramSocketFD createDatagramSocket(scope Address bind_address, scope Address target_address)
|
||||
{
|
||||
auto sock = cast(DatagramSocketFD)createSocket(bind_address.addressFamily, SOCK_DGRAM);
|
||||
if (sock == -1) return DatagramSocketFD.invalid;
|
||||
|
@ -646,6 +656,12 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
|||
return sock;
|
||||
}
|
||||
|
||||
final override bool setBroadcast(DatagramSocketFD socket, bool enable)
|
||||
{
|
||||
int tmp_broad = enable;
|
||||
return () @trusted { return setsockopt(socket, SOL_SOCKET, SO_BROADCAST, &tmp_broad, tmp_broad.sizeof); } () == 0;
|
||||
}
|
||||
|
||||
void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish)
|
||||
@trusted { // DMD 2.072.0-b2: scope considered unsafe
|
||||
import std.typecons : scoped;
|
||||
|
|
|
@ -82,6 +82,11 @@ final class WinAPIEventDriverCore : EventDriverCore {
|
|||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
protected override void* rawUserData(DatagramSocketFD descriptor, size_t size, DataInitializer initialize, DataInitializer destroy) @system
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
}
|
||||
|
||||
final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||
|
@ -156,6 +161,11 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
|||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
override bool setBroadcast(DatagramSocketFD socket, bool enable)
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
}
|
||||
|
||||
override void receive(DatagramSocketFD socket, ubyte[] buffer, IOMode mode, DatagramIOCallback on_receive_finish)
|
||||
{
|
||||
assert(false, "TODO!");
|
||||
|
|
Loading…
Reference in a new issue