set SO_KEEPALIVE on client sockets
[quassel.git] / src / core / corenetwork.cpp
index 8f57581..206b019 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2014 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -44,7 +44,6 @@ CoreNetwork::CoreNetwork(const NetworkId &networkid, CoreSession *session)
     _requestedUserModes('-')
 {
     _autoReconnectTimer.setSingleShot(true);
-    _socketCloseTimer.setSingleShot(true);
     connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
 
     setPingInterval(networkConfig()->pingInterval());
@@ -183,6 +182,8 @@ void CoreNetwork::connectToIrc(bool reconnecting)
         socket.setProxy(QNetworkProxy::NoProxy);
     }
 
+    enablePingTimeout();
+
 #ifdef HAVE_SSL
     socket.setProtocol((QSsl::SslProtocol)server.sslVersion);
     if (server.useSsl) {
@@ -438,6 +439,8 @@ void CoreNetwork::socketInitialized()
         return;
 #endif
 
+    socket.setSocketOption(QAbstractSocket::KeepAliveOption, true);
+
     CoreIdentity *identity = identityPtr();
     if (!identity) {
         qCritical() << "Identity invalid!";
@@ -447,8 +450,6 @@ void CoreNetwork::socketInitialized()
 
     emit socketInitialized(identity, localAddress(), localPort(), peerAddress(), peerPort());
 
-    enablePingTimeout();
-
     // TokenBucket to avoid sending too much at once
     _messageDelay = 2200;  // this seems to be a safe value (2.2 seconds delay)
     _burstSize = 5;