This commit is contained in:
Tristan B. Kildaire 2020-04-20 19:39:30 +02:00
parent 93bb1615df
commit 4ef21cdd32
2 changed files with 26 additions and 22 deletions

View File

@ -1,53 +1,53 @@
module server.listeners; module server.listeners;
import server.types; import server.types;
import std.socket : Socket; import std.socket : Socket, Address, AddressFamily, SocketType;
public class UNIXListener : BesterListener public class UNIXListener : BesterListener
{ {
this(BesterServer besterServer, string path) this(BesterServer besterServer, Address address)
{ {
super(besterServer); super(besterServer);
setServerSocket(setupUNIXSocket(path)); setServerSocket(setupUNIXSocket(address));
} }
private Socket setupUNIXSocket(string path) private Socket setupUNIXSocket(Address address)
{ {
Socket unixSocket; Socket unixSocket = new Socket(AddressFamily.UNIX, SocketType.STREAM);
unixSocket.bind(address);
return unixSocket; return unixSocket;
} }
} }
public class TCP4 : BesterListener public class TCP4Listener : BesterListener
{ {
this(BesterServer besterServer, string path) this(BesterServer besterServer, Address address)
{ {
super(besterServer); super(besterServer);
setServerSocket(setupUNIXSocket(path)); setServerSocket(setupTCP4Socket(address));
} }
private Socket setupUNIXSocket(string path) private Socket setupTCP4Socket(Address address)
{ {
Socket unixSocket; Socket tcp4Socket = new Socket(AddressFamily.INET, SocketType.STREAM);
tcp4Socket.bind(address);
return unixSocket; return tcp4Socket;
} }
} }
public class TCP6 : BesterListener public class TCP6Listener : BesterListener
{ {
this(BesterServer besterServer, string path) this(BesterServer besterServer, Address address)
{ {
super(besterServer); super(besterServer);
setServerSocket(setupUNIXSocket(path)); setServerSocket(setupTCP6Socket(address));
} }
private Socket setupUNIXSocket(string path) private Socket setupTCP6Socket(Address address)
{ {
Socket unixSocket; Socket tcp6Socket = new Socket(AddressFamily.INET6, SocketType.STREAM);
tcp6Socket.bind(address);
return unixSocket; return tcp6Socket;
} }
} }

View File

@ -6,6 +6,7 @@ import std.socket : SocketOSException;
import utils.debugging : debugPrint; import utils.debugging : debugPrint;
import std.stdio : File, writeln; import std.stdio : File, writeln;
import std.json : parseJSON, JSONValue; import std.json : parseJSON, JSONValue;
import server.listeners;
JSONValue getConfig(string configurationFilePath) JSONValue getConfig(string configurationFilePath)
{ {
@ -43,6 +44,9 @@ BesterListener[] getListeners(JSONValue networkBlock)
debugPrint("<<< IPv4 TCP Block >>>\n" ~ inet4TCPBlock.toPrettyString()); debugPrint("<<< IPv4 TCP Block >>>\n" ~ inet4TCPBlock.toPrettyString());
string inet4Address = inet4TCPBlock["address"].str(); string inet4Address = inet4TCPBlock["address"].str();
ushort inet4Port = to!(ushort)(inet4TCPBlock["port"].str()); ushort inet4Port = to!(ushort)(inet4TCPBlock["port"].str());
TCP4Listener tcp4Listener = new TCP4Listener();
/* Look for IPv6 TCP block */ /* Look for IPv6 TCP block */
JSONValue inet6TCPBlock = networkBlock["tcp6"]; JSONValue inet6TCPBlock = networkBlock["tcp6"];