Now accepts incoming connections, adds them to the global queue and starts the handler for the new connection

This commit is contained in:
Tristan B. Kildaire 2020-11-03 10:39:56 +02:00
parent 616d063516
commit 2badd2d302
1 changed files with 29 additions and 4 deletions

View File

@ -2,14 +2,16 @@ module dnetd.dlistener;
import std.socket;
import dnetd.dserver;
import core.thread;
import dnetd.dconnection;
public final class DListener
public final class DListener : Thread
{
/* Associated server */
private DServer server;
/* The socket */
private Socket socket;
private Socket serverSocket;
/**
* Creates new listener with the associated server
@ -17,9 +19,11 @@ public final class DListener
*/
this(DServer server, AddressInfo addressInfo)
{
super(&dequeueLoop);
/* Set the server */
this.server = server;
// /* Get the Address */
// Address address = addressInfo.address;
@ -30,6 +34,27 @@ public final class DListener
/* address.addressFamily, addressInfo.type, addressInfo.protocol */
/* Create the Socket and bind it */
socket = new Socket(addressInfo);
serverSocket = new Socket(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);
}
}
}