[Pioneers-commits] r21 - in trunk: . client/gtk common

kemm at garage.maemo.org kemm at garage.maemo.org
Mon Mar 10 13:51:59 EET 2008


Author: kemm
Date: 2008-03-10 13:51:59 +0200 (Mon, 10 Mar 2008)
New Revision: 21

Modified:
   trunk/client/gtk/offline.c
   trunk/common/network.c
   trunk/configure.ac
Log:
Rework network connecting...


Modified: trunk/client/gtk/offline.c
===================================================================
--- trunk/client/gtk/offline.c	2008-03-10 01:50:14 UTC (rev 20)
+++ trunk/client/gtk/offline.c	2008-03-10 11:51:59 UTC (rev 21)
@@ -169,7 +169,7 @@
 
     osso_context = osso_initialize("pioneers", "0.0.2", TRUE, NULL);
     if (osso_context == NULL) {
-        return OSSO_ERROR;
+        return;
     }
     
 	frontend_gui_register_init();

Modified: trunk/common/network.c
===================================================================
--- trunk/common/network.c	2008-03-10 01:50:14 UTC (rev 20)
+++ trunk/common/network.c	2008-03-10 11:51:59 UTC (rev 21)
@@ -50,6 +50,9 @@
 #endif				/* ndef HAVE_GETADDRINFO_ET_AL */
 
 #include <time.h>
+
+#include <conic.h>
+
 #include "config.h"
 #include "driver.h"
 #include "game.h"
@@ -545,16 +548,10 @@
 #endif
 }
 
+static void conic_cb_connected(ConIcConnection *cnx, ConIcConnectionEvent *event, gpointer user_data);
+
 gboolean net_connect(Session * ses, const gchar * host, const gchar * port)
 {
-#ifdef HAVE_GETADDRINFO_ET_AL
-	int err;
-	struct addrinfo hints, *ai, *aip;
-#else
-	gint iii;
-	struct hostent *he;
-	struct sockaddr_in addr;
-#endif				/* HAVE_GETADDRINFO_ET_AL */
 
 	net_close(ses);
 	if (ses->host != NULL)
@@ -564,24 +561,52 @@
 	ses->host = g_strdup(host);
 	ses->port = g_strdup(port);
 
+    if (strcasecmp(host, "localhost") && strcmp(host, "127.0.0.1")) {
+        ConIcConnection *ic;
+        
+        ic = con_ic_connection_new();
+        g_signal_connect(ic, "connection-event", (GCallback)conic_cb_connected, ses);
+        return con_ic_connection_connect(ic, CON_IC_CONNECT_FLAG_NONE);
+    } else {
+        conic_cb_connected(NULL, NULL, ses);
+    }
+
+    return TRUE;
+}
+
+static void conic_cb_connected(ConIcConnection *cnx, ConIcConnectionEvent *event, gpointer user_data)
+{
+    Session *ses = (Session *)user_data;
 #ifdef HAVE_GETADDRINFO_ET_AL
+	int err;
+	struct addrinfo hints, *ai, *aip;
+#else
+	gint iii;
+	struct hostent *he;
+	struct sockaddr_in addr;
+#endif				/* HAVE_GETADDRINFO_ET_AL */
+
+    if (con_ic_connection_event_get_status(event) != CON_IC_STATUS_CONNECTED)
+        return;
+    
+#ifdef HAVE_GETADDRINFO_ET_AL
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = PF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
 	hints.ai_protocol = IPPROTO_TCP;
 
-	if ((err = getaddrinfo(host, port, &hints, &ai))) {
+	if ((err = getaddrinfo(ses->host, ses->port, &hints, &ai))) {
 		log_message(MSG_ERROR,
-			    _("Cannot resolve %s port %s: %s\n"), host,
-			    port, gai_strerror(err));
-		return FALSE;
+			    _("Cannot resolve %s port %s: %s\n"), ses->host,
+			    ses->port, gai_strerror(err));
+		return;
 	}
 	if (!ai) {
 		log_message(MSG_ERROR,
 			    _
 			    ("Cannot resolve %s port %s: host not found\n"),
-			    host, port);
-		return FALSE;
+			    ses->host, ses->port);
+		return;
 	}
 #endif				/* HAVE_GETADDRINFO_ET_AL */
 
@@ -638,7 +663,7 @@
 				log_message(MSG_ERROR,
 					    _
 					    ("Error connecting to %s: %s\n"),
-					    host, net_errormsg());
+					    ses->host, net_errormsg());
 				net_closesocket(ses->fd);
 				ses->fd = -1;
 				continue;
@@ -650,11 +675,6 @@
 #ifdef HAVE_GETADDRINFO_ET_AL
 	freeaddrinfo(ai);
 #endif				/* HAVE_GETADDRINFO_ET_AL */
-
-	if (ses->fd >= 0)
-		return TRUE;
-	else
-		return FALSE;
 }
 
 /* Free and NULL-ify the session *ses */

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2008-03-10 01:50:14 UTC (rev 20)
+++ trunk/configure.ac	2008-03-10 11:51:59 UTC (rev 21)
@@ -372,7 +372,7 @@
 AM_GLIB_GNU_GETTEXT
 AC_DEFINE_UNQUOTED(ALL_LINGUAS, "$ALL_LINGUAS", [Available languages])
 
-PKG_CHECK_MODULES(UI, [ hildon-1 libosso ])
+PKG_CHECK_MODULES(UI, [ hildon-1 libosso conic ])
 AC_SUBST(CFLAGS, "$CFLAGS $UI_CFLAGS")
 AC_SUBST(LIBS, "$LIBS $UI_LIBS")
 



More information about the Pioneers-commits mailing list