mirror of https://github.com/deavminet/dnetd.git
Merge branch 'listeners' into multiple_listeners
This commit is contained in:
commit
b9513bae96
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue