Made ping available for anyone
Added feature to disable autoPing Server can also disable autoPing
This commit is contained in:
parent
76e0c6b31d
commit
79d518f97e
@ -297,7 +297,7 @@ namespace IO {
|
|||||||
_open = false;
|
_open = false;
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
if ((time(nullptr) - commTime) > 1) if (!ping()) { _open = false; close(); }
|
if (autoPing && ((time(nullptr) - commTime) > 1)) if (!ping()) { _open = false; close(); }
|
||||||
}
|
}
|
||||||
bool NetClient::isOpen() { return _open; }
|
bool NetClient::isOpen() { return _open; }
|
||||||
|
|
||||||
@ -362,7 +362,6 @@ namespace IO {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void NetServer::sharedSetup(char* port, std::function<bool(NetClient*)> f) {
|
void NetServer::sharedSetup(char* port, std::function<bool(NetClient*)> f) {
|
||||||
_open = true;
|
_open = true;
|
||||||
timeoutHandler = NULL;
|
timeoutHandler = NULL;
|
||||||
@ -499,6 +498,8 @@ namespace IO {
|
|||||||
|
|
||||||
void NetServer::setOnDestroy(std::function<void()> call) { onDestroy = call; }
|
void NetServer::setOnDestroy(std::function<void()> call) { onDestroy = call; }
|
||||||
|
|
||||||
|
void NetServer::setAutoPing(bool b) { for (NetClient* cli : *clients) cli->autoPing = b; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void writeState(NetClient& cli, const char* stateName, char state) {
|
void writeState(NetClient& cli, const char* stateName, char state) {
|
||||||
|
@ -74,15 +74,17 @@ namespace IO {
|
|||||||
bool _write(char*, ulong_64b); // Internal write function. Doesn't do any of the fancy auto encryption: just raw write...
|
bool _write(char*, ulong_64b); // Internal write function. Doesn't do any of the fancy auto encryption: just raw write...
|
||||||
bool writeBufferedPackets(); // Flushes and deletes buffer
|
bool writeBufferedPackets(); // Flushes and deletes buffer
|
||||||
void update(); // Read incoming data and store in buffers
|
void update(); // Read incoming data and store in buffers
|
||||||
bool ping(); // Check if connection is alive by pinging remote host
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<std::pair<char*, std::pair<ulong_64b, char*>*>*> associatedData;
|
std::vector<std::pair<char*, std::pair<ulong_64b, char*>*>*> associatedData;
|
||||||
std::thread listener; // Incoming data listener (optional)
|
std::thread listener; // Incoming data listener (optional)
|
||||||
SOCKET _socket; // Underlying socket used for communication
|
SOCKET _socket; // Underlying socket used for communication
|
||||||
std::vector<Packet>* packets; // Basically a set containing a backlog of unprocessed data. Will oly be used if event handler doesn't exist
|
std::vector<Packet>* packets; // Basically a set containing a backlog of unprocessed data. Will oly be used if event handler doesn't exist
|
||||||
|
|
||||||
|
|
||||||
std::function<void(NetClient*, Packet)> evt; // New data event handler
|
std::function<void(NetClient*, Packet)> evt; // New data event handler
|
||||||
std::function<void()> onDestroy; // Event handler called when NetClient object is destroyed
|
std::function<void()> onDestroy; // Event handler called when NetClient object is destroyed
|
||||||
public:
|
public:
|
||||||
|
bool autoPing = true; // Whether or not client should actively check connection state
|
||||||
time_t commTime; // Latest time a transaction occurred
|
time_t commTime; // Latest time a transaction occurred
|
||||||
NetClient(char* ipAddr, char* port, CryptoLevel = CryptoLevel::None);// Standard constructor for creating connection
|
NetClient(char* ipAddr, char* port, CryptoLevel = CryptoLevel::None);// Standard constructor for creating connection
|
||||||
NetClient(char* ipAddr, char* port, Crypto::RSA::KeyData&, CryptoLevel);// Standard constructor for creating connection with predefined keys
|
NetClient(char* ipAddr, char* port, Crypto::RSA::KeyData&, CryptoLevel);// Standard constructor for creating connection with predefined keys
|
||||||
@ -104,6 +106,7 @@ namespace IO {
|
|||||||
bool containsKey(const char* name);
|
bool containsKey(const char* name);
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
ulong_64b available();
|
ulong_64b available();
|
||||||
|
bool ping(); // Check if connection is alive by pinging remote host
|
||||||
};
|
};
|
||||||
|
|
||||||
class NetServer {
|
class NetServer {
|
||||||
@ -131,6 +134,7 @@ namespace IO {
|
|||||||
void clearHandlers();
|
void clearHandlers();
|
||||||
void setOnDestroy(std::function<void()>);
|
void setOnDestroy(std::function<void()>);
|
||||||
bool close();
|
bool close();
|
||||||
|
void setAutoPing(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user