Merge branch 'listeners' into multiple_listeners

This commit is contained in:
Tristan B. Kildaire 2020-12-20 17:22:18 +02:00
commit b9513bae96
2 changed files with 70 additions and 0 deletions

64
source/dnetd/dlistener.d Normal file
View File

@ -0,0 +1,64 @@
module dnetd.dlistener;
import std.socket;
import dnetd.dserver;
import core.thread;
import dnetd.dconnection;
import gogga;
import std.conv : to;
public final class DListener : Thread
{
/* Associated server */
private DServer server;
/* The socket */
private Socket serverSocket;
/**
* Creates new listener with the associated server
* and listens on the given address
*/
this(DServer server, AddressInfo addressInfo)
{
super(&dequeueLoop);
/* Set the server */
this.server = server;
// /* Get the Address */
// Address address = addressInfo.address;
/* TODO: Check AF_FAMILY (can only be INET,INET6,UNIX) */
/* TODO: Check SocketType (can only be STREAM) */
/* TODO: Check Protocol, can only be RAW (assuming UNIX) or TCP */
/* address.addressFamily, addressInfo.type, addressInfo.protocol */
/* Create the Socket and bind it */
serverSocket = new Socket(addressInfo);
gprintln("New listener started with address "~to!(string)(addressInfo));
/* Start the connection dequeue thread */
start();
}
private void dequeueLoop()
{
/* Start accepting-and-enqueuing connections */
serverSocket.listen(0); /* TODO: Linux be lile, hehahahhahahah who gives one - I give zero */
while(true)
{
/* Dequeue a connection */
Socket socket = serverSocket.accept();
/* Spawn a connection handler */
DConnection connection = new DConnection(server, socket);
/* Add to the connection queue */
server.addConnection(connection);
}
}
}

View File

@ -20,6 +20,7 @@ import std.stdio;
import std.conv : to;
import dnetd.dconfig;
import dnetd.dlink;
import dnetd.dlistener;
import gogga;
public class DServer : Thread
@ -51,6 +52,11 @@ public class DServer : Thread
*/
private DMeyer meyerSS;
/**
* The listeners attached to this server
*/
private DListener[] listeners;
/* TODO: Implement new constructor */
this(DConfig config)
{