Check if connection to server is successfull.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Fri, 3 Jul 2009 21:13:26 +0000 (18:13 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Fri, 3 Jul 2009 21:15:40 +0000 (18:15 -0300)
popproxy.c

index 3217b00..93464e1 100644 (file)
@@ -45,9 +45,14 @@ server_conn_new (char *server, char *port)
   int fd;
   HCConn *conn;
   HCConn *ssl_conn;
+  fd = hc_tcp_connect (server, port);
+  if (fd < 0)
+    {
+      g_warning ("Could not connect to server at %s:%s.", server, port);
+      return NULL;
+    }
   conn = hc_conn_new (NULL, NULL);
   ssl_conn = hc_conn_new (NULL, NULL);
-  fd = hc_tcp_connect (server, port);
   hc_conn_set_driver_channel (conn, fd);
   hc_conn_set_driver_ssl (ssl_conn, conn);
   return ssl_conn;
@@ -85,11 +90,19 @@ new_client (int fd, struct sockaddr *addr, socklen_t saddr, gpointer data)
     }
   g_message ("Received connection from %s.",
              inet_ntoa (((struct sockaddr_in *) addr)->sin_addr));
+
+  server_conn = server_conn_new (address->server, address->port);
+  if (server_conn == NULL)
+    {
+      return;
+    }
+
   conn = hc_conn_new (NULL, NULL);
   hc_conn_set_driver_channel (conn, fd);
-  server_conn = server_conn_new (address->server, address->port);
+
   hc_conn_set_callback (conn, push_other, server_conn);
   hc_conn_set_callback (server_conn, push_other, conn);
+
 }
 
 static gchar *configfile;