[netperf-dev] netperf4 commit notice r90 - branches/glib_migration/src

raj at netperf.org raj at netperf.org
Tue Mar 21 15:51:46 PST 2006


Author: raj
Date: 2006-03-21 15:51:45 -0800 (Tue, 21 Mar 2006)
New Revision: 90

Modified:
   branches/glib_migration/src/netlib.c
   branches/glib_migration/src/netlib.h
   branches/glib_migration/src/netserver.c
Log:
More steps towards glib eventloop for the main processing. Compiles but
undoubtedly full of holes and bugs.


Modified: branches/glib_migration/src/netlib.c
===================================================================
--- branches/glib_migration/src/netlib.c	2006-03-21 01:25:38 UTC (rev 89)
+++ branches/glib_migration/src/netlib.c	2006-03-21 23:51:45 UTC (rev 90)
@@ -999,9 +999,9 @@
   }
 
 #ifdef WITH_GLIB
-  ret = g_module_symbol(lib_handle,fname,&func);
+  ret  = g_module_symbol(lib_handle,fname,(gpointer *)&func);
 #else
-  func  = (GenReport)dlsym(lib_handle,(char *)fname);
+  func = (GenReport)dlsym(lib_handle,(char *)fname);
 #endif
   if (debug) {
     fprintf(where,"symbol lookup of function '%s' returned %p\n",
@@ -1669,6 +1669,7 @@
   int rc = NPE_SUCCESS;
   gboolean ret;
   server_t *netperf;
+  global_state_t *global_state = data;
 
   NETPERF_DEBUG_ENTRY(debug,where);
 
@@ -1683,14 +1684,14 @@
 		xml_message);
     }
     /* lookup its destination and send it on its way */
-    netperf = netperf_hash[0].server;
+    netperf = global_state->server_hash[0].server;
     /* mutex locking is not required because only one netserver thread
        looks at these data structures per sgb */
     rc = process_message(netperf,message);
     if (rc == NPE_SUCCESS) 
       ret = TRUE;
     else
-      ret = false;
+      ret = FALSE;
   }
   else {
     if (debug) {
@@ -1713,9 +1714,11 @@
   GError *error = NULL;
   gchar *ptr;
   GIOStatus status;
-
+  int ret;
+  global_state_t *global_state;
   NETPERF_DEBUG_ENTRY(debug,where);
-  message_state = data;
+  global_state = data;
+  message_state = global_state->message_state;
   if (debug) {
     g_fprintf(where,
 	      "%s called with cource %p condition %x and data %p\n",

Modified: branches/glib_migration/src/netlib.h
===================================================================
--- branches/glib_migration/src/netlib.h	2006-03-21 01:25:38 UTC (rev 89)
+++ branches/glib_migration/src/netlib.h	2006-03-21 23:51:45 UTC (rev 90)
@@ -121,6 +121,7 @@
 #endif
 
 extern int netperf_complete_filename(char *name, char *full, int fulllen);
+extern gboolean read_from_control_connection(GIOChannel *source, GIOCondition condition, gpointer data);
 
 /* state machine data structure for process message */
 
@@ -139,6 +140,14 @@
   gchar   *buffer;
 } message_state_t;
 
+typedef struct global_state {
+  server_hash_t   *server_hash;   /* where to find netperf/netserver hash */
+  test_hash_t     *test_hash;     /* where to find the test hash */
+  message_state_t *message_state; /* so we can keep track of partials */
+  GMainLoop       *loop;          /* so we can add things to the loop */
+  gboolean        is_netserver;   /* not sure if this is really necessary */
+} global_state_t;
+
 extern void netlib_init();
 
 void display_test_hash();

Modified: branches/glib_migration/src/netserver.c
===================================================================
--- branches/glib_migration/src/netserver.c	2006-03-21 01:25:38 UTC (rev 89)
+++ branches/glib_migration/src/netserver.c	2006-03-21 23:51:45 UTC (rev 90)
@@ -942,9 +942,16 @@
   SOCKET control_socket;
   SOCKET listen_socket;
   gboolean ret;
+  GIOStatus  status;
+  GIOChannel *control_channel;
+  GError   *error=NULL;
+  global_state_t *global_state;
+  guint   watch_id;
 
   g_fprintf(where,"accepting a new connection\n");
 
+  global_state = data;
+
 #ifdef G_OS_WIN32
   listen_socket = g_io_channel_win32_get_fd(source);
 #else
@@ -979,8 +986,39 @@
        "original" way. later we will establish a recv callback for a
        proper glib event loop */
     g_fprintf(where,"accepted a connection but told not to spawn\n");
-    handle_netperf_requests(control_socket);
-    CLOSE_SOCKET(control_socket);
+#ifdef G_OS_WIN32
+    control_channel = g_io_channel_win32_new_socket(control_socket);
+#else
+    control_channel = g_io_channel_unix_new(control_socket);
+#endif
+    status = g_io_channel_set_flags(control_channel,G_IO_FLAG_NONBLOCK,&error);
+    if (error) {
+      g_warning("g_io_channel_set_flags %s %d %s\n",
+		g_quark_to_string(error->domain),
+		error->code,
+		error->message);
+      g_clear_error(&error);
+    }
+    g_print("status after set flags %d control_channel %p\n",status,control_channel);
+    
+    status = g_io_channel_set_encoding(control_channel,NULL,&error);
+    if (error) {
+      g_warning("g_io_channel_set_encoding %s %d %s\n",
+		g_quark_to_string(error->domain),
+		error->code,
+		error->message);
+      g_clear_error(&error);
+    }
+    
+    g_print("status after set_encoding %d\n");
+    
+    g_io_channel_set_buffered(control_channel,FALSE);
+    
+    watch_id = g_io_add_watch(control_channel, 
+			      G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
+			      read_from_control_connection,
+			      data);
+    g_print("added watch id %d\n",watch_id);
   }
 
   return(TRUE);
@@ -1270,6 +1308,7 @@
   GError *error = NULL;
   GIOStatus status;
   GMainLoop *loop;
+  global_state_t *global_state_ptr;
 
 #ifdef G_OS_WIN32
   WSADATA	wsa_data ;
@@ -1393,6 +1432,13 @@
 
   loop = g_main_loop_new(NULL, FALSE);
 
+  global_state_ptr                = g_malloc(sizeof(global_state_t));
+  global_state_ptr->server_hash   = netperf_hash;
+  global_state_ptr->test_hash     = test_hash;
+  global_state_ptr->message_state = g_malloc(sizeof(message_state_t));
+  global_state_ptr->is_netserver  = TRUE;
+  global_state_ptr->loop          = loop;
+
   if (need_setup) {
     listen_sock = setup_listen_endpoint(listen_port);
 #ifdef G_OS_WIN32
@@ -1427,7 +1473,7 @@
     watch_id = g_io_add_watch(control_channel, 
 			      G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
 			      accept_connection,
-			      loop);
+			      global_state_ptr);
     g_print("added watch id %d\n",watch_id);
 
     g_print("Starting loop to accept stuff...\n");
@@ -1436,7 +1482,46 @@
 
   }
   else {
-    handle_netperf_requests(sock);
+    /* we used to call handle_netperf_requests(sock); here, now we use
+       the loop, luke... */
+#ifdef G_OS_WIN32
+    control_channel = g_io_channel_win32_new_socket(control_socket);
+#else
+    control_channel = g_io_channel_unix_new(control_socket);
+#endif
+    status = g_io_channel_set_flags(control_channel,G_IO_FLAG_NONBLOCK,&error);
+    if (error) {
+      g_warning("g_io_channel_set_flags %s %d %s\n",
+		g_quark_to_string(error->domain),
+		error->code,
+		error->message);
+      g_clear_error(&error);
+    }
+    g_print("status after set flags %d control_channel %p\n",status,control_channel);
+    
+    status = g_io_channel_set_encoding(control_channel,NULL,&error);
+    if (error) {
+      g_warning("g_io_channel_set_encoding %s %d %s\n",
+		g_quark_to_string(error->domain),
+		error->code,
+		error->message);
+      g_clear_error(&error);
+    }
+    
+    g_print("status after set_encoding %d\n");
+    
+    g_io_channel_set_buffered(control_channel,FALSE);
+    
+    /* loop is passed just to have something passed */
+    watch_id = g_io_add_watch(control_channel, 
+			      G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
+			      read_from_control_connection,
+			      global_state_ptr);
+    g_print("added watch id %d\n",watch_id);
+
+    g_print("Starting loop to accept stuff...\n");
+    g_main_loop_run(loop);
+    g_print("Came out of the main loop\n");
   }
 }
 



More information about the netperf-dev mailing list