Disconnect if ping is not received for 30 seconds
This commit is contained in:
parent
b99313a73a
commit
2626035bc2
3 changed files with 15 additions and 1 deletions
|
@ -1230,6 +1230,11 @@ static gboolean disconnectMe(void *data) {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean pingTimeout(void *data) {
|
||||
np->checkPing();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text){
|
||||
PurpleAccount *account = purple_connection_get_account(gc);
|
||||
np->handleDisconnected(np->m_accounts[account], (int) reason, text ? text : "");
|
||||
|
@ -1960,6 +1965,7 @@ int main(int argc, char **argv) {
|
|||
m_sock = create_socket(host, port);
|
||||
|
||||
purple_input_add(m_sock, PURPLE_INPUT_READ, &transportDataReceived, NULL);
|
||||
purple_timeout_add_seconds(30, pingTimeout, NULL);
|
||||
|
||||
np = new SpectrumNetworkPlugin(host, port);
|
||||
bool libev = KEYFILE_STRING("service", "eventloop") == "libev";
|
||||
|
|
|
@ -214,7 +214,8 @@ class NetworkPlugin {
|
|||
virtual void handleExitRequest() { exit(1); }
|
||||
void handleDataRead(std::string &data);
|
||||
virtual void sendData(const std::string &string) {}
|
||||
|
||||
|
||||
void checkPing();
|
||||
|
||||
private:
|
||||
void handleLoginPayload(const std::string &payload);
|
||||
|
|
|
@ -553,6 +553,13 @@ void NetworkPlugin::send(const std::string &data) {
|
|||
sendData(std::string(header, 4) + data);
|
||||
}
|
||||
|
||||
void NetworkPlugin::checkPing() {
|
||||
if (m_pingReceived == false) {
|
||||
handleExitRequest();
|
||||
}
|
||||
m_pingReceived = false;
|
||||
}
|
||||
|
||||
void NetworkPlugin::sendPong() {
|
||||
m_pingReceived = true;
|
||||
std::string message;
|
||||
|
|
Loading…
Add table
Reference in a new issue