Added new system
This commit is contained in:
parent
57e72899e3
commit
7de5d00c60
|
@ -20,6 +20,8 @@ public final class Watcher : Thread
|
||||||
|
|
||||||
private bool running;
|
private bool running;
|
||||||
|
|
||||||
|
|
||||||
|
private bool newSys;
|
||||||
private SocketSet socketSetR, socketSetW, socketSetE;
|
private SocketSet socketSetR, socketSetW, socketSetE;
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,13 +30,19 @@ public final class Watcher : Thread
|
||||||
*/
|
*/
|
||||||
private Duration timeOut;
|
private Duration timeOut;
|
||||||
|
|
||||||
this(Manager manager, Socket endpoint, Duration timeOut = dur!("msecs")(100))
|
this(Manager manager, Socket endpoint, Duration timeOut = dur!("msecs")(100), bool newSys = false)
|
||||||
{
|
{
|
||||||
super(&run);
|
super(&run);
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
|
|
||||||
|
|
||||||
|
this.newSys = newSys;
|
||||||
|
if(newSys)
|
||||||
|
{
|
||||||
initSelect();
|
initSelect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.timeOut = timeOut;
|
this.timeOut = timeOut;
|
||||||
|
|
||||||
|
@ -71,43 +79,78 @@ public final class Watcher : Thread
|
||||||
byte[] receivedPayload;
|
byte[] receivedPayload;
|
||||||
|
|
||||||
|
|
||||||
|
if(newSys)
|
||||||
/* We want to check if `endpoint` can be read from */
|
{
|
||||||
|
/**
|
||||||
|
* We want to check the readable status of the `endpoint` socket, we use
|
||||||
|
* the `select()` function for this. However, after selecting it will need
|
||||||
|
* to be re-added if you want to check again. Example, if you add it to
|
||||||
|
* the `socketSetR` (the readable-socketset) then if we time out or it
|
||||||
|
* is not readable from it will be removed from said set.
|
||||||
|
*
|
||||||
|
* Therefore we will need to add it back again for our next check (via
|
||||||
|
* calling `select()`)
|
||||||
|
*/
|
||||||
socketSetR.add(endpoint);
|
socketSetR.add(endpoint);
|
||||||
|
int status = Socket.select(socketSetR, null, null, timeOut);
|
||||||
|
|
||||||
/* Check if the endpoint has any data available */
|
import std.stdio : writeln;
|
||||||
int status = Socket.select(socketSetR, socketSetW, socketSetE, timeOut);
|
|
||||||
|
|
||||||
/* If we timed out on the select() */
|
/* If we timed out on the select() */
|
||||||
if(status == 0)
|
if(status == 0)
|
||||||
{
|
{
|
||||||
/* Check if we need to exit */
|
/* Check if we need to exit */
|
||||||
|
writeln("We got 0");
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Interrupt */
|
/* Interrupt */
|
||||||
else if (status == -1)
|
else if (status == -1)
|
||||||
{
|
{
|
||||||
/* TODO: Not sure what we should do here */
|
/* TODO: Not sure what we should do here */
|
||||||
|
writeln("We got -1");
|
||||||
|
|
||||||
|
import core.stdc.errno;
|
||||||
|
writeln(errno);
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
/* Either data is available or a network occurred */
|
/* Either data is available or a network occurred */
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
writeln("Info: ", endpoint.isAlive);
|
||||||
|
writeln("info: ", endpoint.handle);
|
||||||
|
|
||||||
|
writeln("We got ", status);
|
||||||
|
|
||||||
|
|
||||||
|
/* If the socket is still connected */
|
||||||
|
if(endpoint.isAlive())
|
||||||
{
|
{
|
||||||
/* If we have data */
|
/* If we have data */
|
||||||
if(socketSetR.isSet(endpoint))
|
if(socketSetR.isSet(endpoint))
|
||||||
{
|
{
|
||||||
/* Do nothing (fall through) */
|
/* Do nothing (fall through) */
|
||||||
|
writeln("We got ready socket");
|
||||||
|
|
||||||
|
/* I don't want to do mulitple additions, so let's clear the socket read set */
|
||||||
|
socketSetR.reset();
|
||||||
}
|
}
|
||||||
/* We have an error */
|
|
||||||
|
/* There is no else as the only socket set checked for IS read */
|
||||||
|
}
|
||||||
|
/* If the socket is not connected (network error) */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* TODO: Handle this */
|
/* TODO: Maybe handle? */
|
||||||
}
|
writeln("We have socket error");
|
||||||
|
|
||||||
|
// throw new TristanableException(manager, "Network error with endpoint socket");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
socketSetR.reset();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Block for socket response */
|
/* Block for socket response */
|
||||||
bool recvStatus = receiveMessage(endpoint, receivedPayload);
|
bool recvStatus = receiveMessage(endpoint, receivedPayload);
|
||||||
|
|
Loading…
Reference in New Issue