added auto reconnect
authorpk910 <philipp@zoelle1.de>
Mon, 24 Oct 2011 00:09:30 +0000 (02:09 +0200)
committerpk910 <philipp@zoelle1.de>
Mon, 24 Oct 2011 00:11:01 +0000 (02:11 +0200)
src/ClientSocket.c
src/ClientSocket.h
src/main.h

index cda3ee76adeb93b82501db4b305fc05322ef7aa1..f9faf44807eaf8b7f896704409ef8dc2e529e738 100644 (file)
@@ -98,7 +98,7 @@ int connect_socket(struct ClientSocket *client) {
     }
 
     client->sock = sock;
-    client->flags |= SOCKET_FLAG_CONNECTED;
+    client->flags |= SOCKET_FLAG_CONNECTED | SOCKET_FLAG_RECONNECT;
     client->connection_time = time(0);
 
     //send the IRC Headers
@@ -151,7 +151,7 @@ int connect_socket(struct ClientSocket *client) {
     }
 
     client->sock = sock;
-    client->flags |= SOCKET_FLAG_CONNECTED;
+    client->flags |= SOCKET_FLAG_CONNECTED | SOCKET_FLAG_RECONNECT;
     client->connection_time = time(0);
 
     //send the IRC Headers
@@ -275,6 +275,10 @@ void socket_loop(int timeout_seconds) {
                     sock->bufferpos -= used;
                 }
             }
+        } else if(!(sock->flags & SOCKET_FLAG_CONNECTED) && (sock->flags & SOCKET_FLAG_RECONNECT)) {
+            if(time(0) - sock->connection_time >= SOCKET_RECONNECT_TIME) {
+                connect_socket(sock);
+            }
         }
     }
 }
index 7926767c973b0135b6077c2cc1f3938e8ee2884b..01a8eeeff3e7f2a985228209e742167ee4d0631b 100644 (file)
@@ -24,6 +24,7 @@
 #define SOCKET_FLAG_READY     0x04
 #define SOCKET_FLAG_PREFERRED 0x08 /* prefered bot to send datas to the IRC World (NOTICE's WHO's etc pp) */
 #define SOCKET_FLAG_USE_QUEUE 0x10
+#define SOCKET_FLAG_RECONNECT 0x20
 
 #define BUF_SIZ 512
 
index 811ad48cd2f930e5918b511b3999df6d2388f845..e49f5b46a0257032f9d07384d8a2c49cda6b1666 100644 (file)
@@ -73,7 +73,8 @@
 #define COMPILER "Unknown"
 #endif
 
-#define SOCKET_SELECT_TIME 1
+#define SOCKET_SELECT_TIME    1
+#define SOCKET_RECONNECT_TIME 20
 
 #define NICKLEN         30
 #define USERLEN         10