Pushed some shut

This commit is contained in:
Tristan B. Kildaire 2021-01-20 18:11:03 +02:00
parent 738eb9397b
commit 2553978839
1 changed files with 30 additions and 17 deletions

View File

@ -2,7 +2,7 @@ module server.listeners;
import core.thread : Thread; import core.thread : Thread;
import server.listener : ButterflyListener; import server.listener : ButterflyListener;
import std.socket : Socket, Address, SocketType, ProtocolType, parseAddress; import std.socket : Socket, Address, SocketType, ProtocolType, parseAddress, AddressFamily;
import std.json : JSONValue; import std.json : JSONValue;
import client.client; import client.client;
import std.conv : to; import std.conv : to;
@ -20,14 +20,21 @@ public class IPv4Listener : ButterflyListener
Address bindAddress = parseAddress(config["address"].str(), to!(ushort)(config["port"].str())); Address bindAddress = parseAddress(config["address"].str(), to!(ushort)(config["port"].str()));
/** /* TODO: Throw an exception if not IPv4 */
* Instantiate a new Socket for the given Address if(bindAddress.addressFamily() == AddressFamily.INET)
* `bindAddress` of which it will bind to. {
*/ /**
serverSocket = new Socket(bindAddress.addressFamily, SocketType.STREAM, ProtocolType.TCP); * Instantiate a new Socket for the given Address
serverSocket.bind(bindAddress); * `bindAddress` of which it will bind to.
*/
serverSocket = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.TCP);
serverSocket.bind(bindAddress);
}
else
{
/* TODO: Throw an exception if not IPv4 */
}
} }
public override void run() public override void run()
@ -60,14 +67,20 @@ public class IPv6Listener : ButterflyListener
Address bindAddress = parseAddress(config["address"].str(), to!(ushort)(config["port"].str())); Address bindAddress = parseAddress(config["address"].str(), to!(ushort)(config["port"].str()));
/** /* TODO: Throw an exception if not IPv6 */
* Instantiate a new Socket for the given Address if(bindAddress.addressFamily() == AddressFamily.INET6)
* `bindAddress` of which it will bind to. {
*/ /**
serverSocket = new Socket(bindAddress.addressFamily, SocketType.STREAM, ProtocolType.TCP); * Instantiate a new Socket for the given Address
serverSocket.bind(bindAddress); * `bindAddress` of which it will bind to.
*/
serverSocket = new Socket(AddressFamily.INET6, SocketType.STREAM, ProtocolType.TCP);
serverSocket.bind(bindAddress);
}
else
{
/* TODO: Throw an exception if not IPv6 */
}
} }
public override void run() public override void run()