mirror of
https://github.com/besterprotocol/besterd
synced 2023-12-13 21:00:32 +01:00
Implementing different listeners for supporting Unix, INET4 and INET6 tcp
This commit is contained in:
parent
1c35bcd793
commit
8978f057a3
20
source/server/listeners.d
Normal file
20
source/server/listeners.d
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module server.listeners;
|
||||||
|
|
||||||
|
import server.types;
|
||||||
|
import std.socket : Socket;
|
||||||
|
|
||||||
|
public class UNIXListener : BesterListener
|
||||||
|
{
|
||||||
|
this(BesterServer besterServer, string path)
|
||||||
|
{
|
||||||
|
super(besterServer);
|
||||||
|
setServerSocket(setupUNIXSocket(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Socket setupUNIXSocket(string path)
|
||||||
|
{
|
||||||
|
Socket unixSocket;
|
||||||
|
|
||||||
|
return unixSocket;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,20 +2,58 @@ module server.types;
|
||||||
|
|
||||||
import utils.debugging : debugPrint;
|
import utils.debugging : debugPrint;
|
||||||
import std.conv : to;
|
import std.conv : to;
|
||||||
import std.socket : Socket, AddressFamily, SocketType, ProtocolType, parseAddress, SocketFlags;
|
import std.socket : Socket, AddressFamily, SocketType, ProtocolType, parseAddress, SocketFlags, Address;
|
||||||
import core.thread : Thread;
|
import core.thread : Thread;
|
||||||
import std.stdio : writeln, File;
|
import std.stdio : writeln, File;
|
||||||
import std.json : JSONValue, parseJSON, JSONException, JSONType, toJSON;
|
import std.json : JSONValue, parseJSON, JSONException, JSONType, toJSON;
|
||||||
import std.string : cmp;
|
import std.string : cmp;
|
||||||
import server.handler;
|
import server.handler;
|
||||||
|
import server.listeners;
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Implement me */
|
/* TODO: Implement me */
|
||||||
/* All this will do is accept incoming connections
|
/* All this will do is accept incoming connections
|
||||||
* but they will be pooled in the BesterServer.
|
* but they will be pooled in the BesterServer.
|
||||||
*/
|
*/
|
||||||
public class BesterListener
|
public class BesterListener : Thread
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* The associated BesterServer */
|
||||||
|
private BesterServer server;
|
||||||
|
|
||||||
|
/* The server's socket */
|
||||||
|
private Socket serverSocket;
|
||||||
|
|
||||||
|
this(BesterServer besterServer)
|
||||||
|
{
|
||||||
|
this.server = besterServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerSocket(Socket serverSocket)
|
||||||
|
{
|
||||||
|
/* Set the server socket */
|
||||||
|
this.serverSocket = serverSocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Start listen loop */
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
serverSocket.listen(1); /* TODO: This value */
|
||||||
|
debugPrint("Server listen loop started");
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
/* Wait for an incoming connection */
|
||||||
|
Socket clientConnection = serverSocket.accept();
|
||||||
|
|
||||||
|
/* Create a new client connection handler and start its thread */
|
||||||
|
BesterConnection besterConnection = new BesterConnection(clientConnection, server);
|
||||||
|
besterConnection.start();
|
||||||
|
|
||||||
|
/* Add this client to the list of connected clients */
|
||||||
|
server.clients ~= besterConnection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +72,7 @@ public class BesterServer
|
||||||
private Socket serverSocket;
|
private Socket serverSocket;
|
||||||
|
|
||||||
/* Connected clients */
|
/* Connected clients */
|
||||||
private BesterConnection[] clients;
|
public BesterConnection[] clients;
|
||||||
|
|
||||||
this(JSONValue config)
|
this(JSONValue config)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue