1
0
mirror of https://github.com/deavmi/birchwood synced 2024-09-20 14:43:23 +02:00

Merge branch 'master' into ircv3

This commit is contained in:
Tristan B. Velloza Kildaire 2023-03-18 12:30:10 +02:00
commit 8d1fbbdece
3 changed files with 43 additions and 7 deletions

View File

@ -26,12 +26,16 @@ __gshared static this()
// TODO: Make abstract and for unit tests make a `DefaultClient` // TODO: Make abstract and for unit tests make a `DefaultClient`
// ... which logs outputs for the `onX()` handler functions // ... which logs outputs for the `onX()` handler functions
/**
* IRC client
*/
public class Client : Thread public class Client : Thread
{ {
/** /**
* Connection information * Connection information
*/ */
private ConnectionInfo connInfo; package shared ConnectionInfo connInfo;
/* TODO: We should learn some info in here (or do we put it in connInfo)? */ /* TODO: We should learn some info in here (or do we put it in connInfo)? */
private string serverName; //TODO: Make use of private string serverName; //TODO: Make use of
@ -42,9 +46,13 @@ public class Client : Thread
package Socket socket; package Socket socket;
/** /**
* Receive queue and send queue managers * Receive queue meneger
*/ */
private ReceiverThread receiver; private ReceiverThread receiver;
/**
* Send queue manager
*/
private SenderThread sender; private SenderThread sender;
/** /**
@ -54,6 +62,14 @@ public class Client : Thread
package bool running = false; package bool running = false;
/**
* Constructs a new IRC client with the given configuration
* info
*
* Params:
* connInfo = the connection parameters
*/
this(ConnectionInfo connInfo) this(ConnectionInfo connInfo)
{ {
super(&loop); super(&loop);
@ -66,12 +82,20 @@ public class Client : Thread
this.sender = new SenderThread(this); this.sender = new SenderThread(this);
} }
/**
* TODO: ANything worth callin on destruction?
*/
~this() ~this()
{ {
//TODO: Do something here, tare downs //TODO: Do something here, tare downs
} }
// TODO: Investigate /**
* Retrieve the active configuration at this
* moment
*
* Returns: the ConnectionInfo struct
*/
public ConnectionInfo getConnInfo() public ConnectionInfo getConnInfo()
{ {
return connInfo; return connInfo;

View File

@ -129,7 +129,7 @@ public final class SenderThread : Thread
foreach(ubyte[] message; sendQueue[]) foreach(ubyte[] message; sendQueue[])
{ {
client.socket.send(message); client.socket.send(message);
Thread.sleep(dur!("seconds")(client.getConnInfo().getFakeLag())); Thread.sleep(dur!("seconds")(client.connInfo.getFakeLag()));
} }
/* Empty the send queue */ /* Empty the send queue */

View File

@ -10,7 +10,7 @@ import birchwood.client.exceptions;
* Represents the connection details for a server * Represents the connection details for a server
* to connect to * to connect to
*/ */
public struct ConnectionInfo public shared struct ConnectionInfo
{ {
/** /**
* Server address * Server address
@ -54,7 +54,8 @@ public struct ConnectionInfo
*/ */
private this(Address addrInfo, string nickname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...") private this(Address addrInfo, string nickname, ulong bulkReadSize = 20, string quitMessage = "birchwood client disconnecting...")
{ {
this.addrInfo = addrInfo; // NOTE: Not sure if much mutable in Address anyways
this.addrInfo = cast(shared Address)addrInfo;
this.nickname = nickname; this.nickname = nickname;
this.bulkReadSize = bulkReadSize; this.bulkReadSize = bulkReadSize;
this.quitMessage = quitMessage; this.quitMessage = quitMessage;
@ -73,6 +74,17 @@ public struct ConnectionInfo
return this.bulkReadSize; return this.bulkReadSize;
} }
/**
* Sets the read-dequeue size
*
* Params:
* bytes = the number of bytes to dequeue at a time
*/
public void setBulkReadSize(ulong bytes)
{
this.bulkReadSize = bytes;
}
/** /**
* Get the address of the endpoint server * Get the address of the endpoint server
* *
@ -80,7 +92,7 @@ public struct ConnectionInfo
*/ */
public Address getAddr() public Address getAddr()
{ {
return addrInfo; return cast(Address)addrInfo;
} }
/** /**