Get configuration details

This commit is contained in:
Tristan B. Kildaire 2020-04-20 19:23:59 +02:00
parent e1b01cf8c5
commit 92d524147d
2 changed files with 34 additions and 1 deletions

View File

@ -32,11 +32,42 @@ JSONValue getConfig(string configurationFilePath)
return config;
}
BesterListener[] getListeners(JSONValue networkBlock)
{
BesterListener[] listeners;
/* TODO: Error handling */
/* Look for IPv4 TCP block */
JSONValue inet4TCPBlock = networkBlock["tcp4"];
string inet4Address = inet4TCPBlock["address"].str();
ushort inet4Port = to!(ushort)(inet4TCPBlock["port"].str());
/* Look for IPv6 TCP block */
JSONValue inet6TCPBlock = networkBlock["tcp6"];
string inet6Address = inet6TCPBlock["address"].str();
ushort inet6Port = to!(ushort)(inet6TCPBlock["port"].str());
/* Look for UNIX Domain block */
JSONValue unixDomainBlock = networkBlock["unix"];
return listeners;
}
void startServer(string configurationFilePath)
{
/* The server configuration */
JSONValue serverConfiguration = getConfig(configurationFilePath);
writeln(serverConfiguration);
debugPrint("<<< Bester.d configuration >>>\n" ~ serverConfiguration.toPrettyString());
/* TODO: Bounds anc type checking */
/* Get the network block */
JSONValue networkBlock = serverConfiguration["network"];
/* TODO: Get keys */
BesterListener[] listeners = getListeners(networkBlock);
/* The server */
BesterServer server = null;

View File

@ -76,6 +76,7 @@ public class BesterServer
private Socket serverSocket;
/* TODO: The above to be replaced */
/* Socket listeners for incoming connections */
private BesterListener[] listeners;
/* Connected clients */
@ -84,6 +85,7 @@ public class BesterServer
/* Construct a new BesterServer with the given listeners */
this(BesterListener[] listeners)
{
/* Set the listeners */
this.listeners = listeners;
}