You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2006/02/14 09:06:26 UTC

svn commit: r377667 - in /webservices/axis2/trunk/c: configure.ac include/axis2_http_server.h modules/core/transport/http/receiver/http_server.c modules/core/transport/http/receiver/http_svr_thread.c modules/core/transport/http/server/http_server_main.c

Author: sahan
Date: Tue Feb 14 00:06:26 2006
New Revision: 377667

URL: http://svn.apache.org/viewcvs?rev=377667&view=rev
Log:
Added signal handler function. Compile time option to disable multi threading

Modified:
    webservices/axis2/trunk/c/configure.ac
    webservices/axis2/trunk/c/include/axis2_http_server.h
    webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_server.c
    webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c
    webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c

Modified: webservices/axis2/trunk/c/configure.ac
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/configure.ac?rev=377667&r1=377666&r2=377667&view=diff
==============================================================================
--- webservices/axis2/trunk/c/configure.ac (original)
+++ webservices/axis2/trunk/c/configure.ac Tue Feb 14 00:06:26 2006
@@ -128,6 +128,21 @@
   CFLAGS=""
 )
 
+AC_ARG_ENABLE(tests, [  --enable-multi_threaded  enable trace. default=yes],
+[ case "${enableval}" in
+  no)
+    AC_MSG_RESULT(no)
+    CFLAGS=""
+    ;;
+  *)
+    AC_MSG_RESULT(yes)
+    CFLAGS="$CFLAGS -DAXIS2_SVR_MULTI_THREADED"
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+  CFLAGS=""
+)
+
 PKG_CHECK_MODULES(XML2, libxml-2.0)
 AC_SUBST(XML2_CFLAGS)
 AC_SUBST(XML2_LIBS)

Modified: webservices/axis2/trunk/c/include/axis2_http_server.h
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/include/axis2_http_server.h?rev=377667&r1=377666&r2=377667&view=diff
==============================================================================
--- webservices/axis2/trunk/c/include/axis2_http_server.h (original)
+++ webservices/axis2/trunk/c/include/axis2_http_server.h Tue Feb 14 00:06:26 2006
@@ -42,6 +42,9 @@
 AXIS2_DECLARE(axis2_transport_receiver_t *) 
 axis2_http_server_create (axis2_env_t **env, axis2_char_t *repo, int port);
 
+axis2_status_t AXIS2_CALL 
+axis2_http_server_stop(axis2_transport_receiver_t *server, axis2_env_t **env);
+
 
 /** @} */
 #ifdef __cplusplus

Modified: webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_server.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_server.c?rev=377667&r1=377666&r2=377667&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_server.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_server.c Tue Feb 14 00:06:26 2006
@@ -203,8 +203,8 @@
 		AXIS2_HTTP_SVR_THREAD_DESTROY(AXIS2_INTF_TO_IMPL(server)->svr_thread, 
 						env);
 	}
-	AXIS2_LOG_INFO((*env)->log, "Successfully terminated  HTTP server\
-						thread");
+	AXIS2_LOG_INFO((*env)->log, "Successfully terminated  HTTP server"
+						" thread");
 	return AXIS2_SUCCESS;
 }
 

Modified: webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c?rev=377667&r1=377666&r2=377667&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/receiver/http_svr_thread.c Tue Feb 14 00:06:26 2006
@@ -172,11 +172,15 @@
 	{
 		int socket = -1;
 	 	axis2_http_svr_thd_args_t *arg_list = NULL;
+		axis2_thread_t *worker_thread = NULL;
 		
 		socket = axis2_network_handler_svr_socket_accept(env, 
 						svr_thread_impl->listen_socket);
 		if(NULL == svr_thread_impl->worker)
 		{
+			AXIS2_LOG_WARNING((*env)->log, AXIS2_LOG_SI, "Worker not ready yet."
+						" Cannot serve the request");
+			axis2_network_handler_close_socket(env, socket);
 			continue;
 		}
 		arg_list = AXIS2_MALLOC((*env)->allocator, 
@@ -190,9 +194,19 @@
 		arg_list->env = env;
 		arg_list->socket = socket;
 		arg_list->worker = svr_thread_impl->worker;
-		AXIS2_THREAD_POOL_GET_THREAD((*env)->thread_pool, worker_func, 
+#ifdef AXIS2_SVR_MULTI_THREADED
+		worker_thread = AXIS2_THREAD_POOL_GET_THREAD((*env)->thread_pool, worker_func, 
 						(void*)arg_list);
-		/*worker_func(NULL, (void*)arg_list);*/
+		if(NULL == worker_thread)
+		{
+			AXIS2_LOG_ERROR((*env)->log, AXIS2_LOG_SI, "Thread creation failed"
+						"server thread loop");
+			continue;
+		}
+		AXIS2_THREAD_POOL_THREAD_DETACH((*env)->thread_pool, worker_thread);
+#else
+		worker_func(NULL, (void*)arg_list);
+#endif
 	}
     return AXIS2_SUCCESS;
 }
@@ -212,7 +226,8 @@
 		return AXIS2_SUCCESS;
 	}
 	svr_thread_impl->stopped = AXIS2_TRUE;
-	AXIS2_LOG_DEBUG((*env)->log, AXIS2_LOG_SI, "Destrying HTTP server thread.");
+	AXIS2_LOG_DEBUG((*env)->log, AXIS2_LOG_SI, "Terminating HTTP server "
+						"thread.");
 	if(svr_thread_impl->listen_socket)
 	{
 		axis2_network_handler_close_socket(env, svr_thread_impl->listen_socket);
@@ -295,7 +310,7 @@
 	status = AXIS2_HTTP_WORKER_PROCESS_REQUEST(tmp, &thread_env, svr_conn, 
 						request);
 	AXIS2_SIMPLE_HTTP_SVR_CONN_FREE(svr_conn, &thread_env);
-	AXIS2_FREE((*env)->allocator, arg_list);
+	AXIS2_FREE(thread_env->allocator, arg_list);
 	AXIS2_PLATFORM_GET_TIME_IN_MILLIS(&t2);
 	millisecs = t2.millitm - t1.millitm;
 	secs = difftime(t2.time, t1.time);
@@ -315,5 +330,8 @@
 						"Error occured in processing request (%.3f seconds)", 
 						secs);
 	}
+#ifdef AXIS2_SVR_MULTI_THREADED
+	AXIS2_THREAD_POOL_EXIT_THREAD((*env)->thread_pool, thd);
+#endif
 	return NULL;
 }

Modified: webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c?rev=377667&r1=377666&r2=377667&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c (original)
+++ webservices/axis2/trunk/c/modules/core/transport/http/server/http_server_main.c Tue Feb 14 00:06:26 2006
@@ -22,12 +22,15 @@
 #include <axis2_error_default.h>
 #include <axis2_log_default.h>
 #include <axis2_thread_pool.h>
+#include <signal.h>
 
-
+axis2_env_t *system_env = NULL;
+axis2_transport_receiver_t *server = NULL;
 /***************************** Function headers *******************************/
 axis2_env_t* init_syetem_env(axis2_allocator_t *allocator, axis2_char_t *log_file);
-void system_exit(axis2_allocator_t *allocator, axis2_env_t *env, int status);
+void system_exit(axis2_env_t *env, int status);
 void usage(axis2_char_t* prog_name);
+void sig_handler(int signal);
 /***************************** End of function headers ************************/
 axis2_env_t* init_syetem_env(axis2_allocator_t *allocator, axis2_char_t *log_file)
 {
@@ -38,16 +41,12 @@
 						thread_pool);
 }
 
-void system_exit(axis2_allocator_t *allocator, axis2_env_t *env, int status)
+void system_exit(axis2_env_t *env, int status)
 {
 	if(NULL != env)
 	{
 		axis2_env_free(env);
 	}
-	if(NULL != allocator)
-	{
-	/*	axis2_allocator_free(allocator); */
-	}
 	_exit(status);
 }
 
@@ -55,7 +54,6 @@
 {
 	axis2_allocator_t *allocator = NULL;
 	axis2_env_t *env = NULL;
-	axis2_transport_receiver_t *server = NULL;
     extern char *optarg;
     extern int optopt;
     int c;
@@ -110,14 +108,16 @@
 	if(NULL == allocator)
 	{
 		printf("[Axis2]Startup FAILED due to memory allocation failure\n");
-		system_exit(NULL, NULL, -1);
+		system_exit(NULL, -1);
 	}
 	
     env = init_syetem_env(allocator, log_file);
     env->log->level = log_level;
 	
     axis2_error_init();
-    
+	system_env = env;
+    signal(SIGINT, sig_handler);
+	signal(SIGPIPE, sig_handler);
 	AXIS2_LOG_INFO(env->log, "Starting Axis2 HTTP server....");
 	AXIS2_LOG_INFO(env->log, "Server port : %d", port);
 	AXIS2_LOG_INFO(env->log, "Repo location : %s", repo_path);
@@ -129,7 +129,7 @@
 	    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Server creation failed: Error code:"
 						" %d :: %s", env->error->error_number,
                         AXIS2_ERROR_GET_MESSAGE(env->error));
-		system_exit(allocator, env, -1);
+		system_exit(env, -1);
 		
 	}
 	printf("Started Simple Axis2 HTTP Server ...\n");
@@ -138,7 +138,7 @@
 		AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Server start failed: Error code:"
 						" %d :: %s", env->error->error_number,
                         AXIS2_ERROR_GET_MESSAGE(env->error));
-		system_exit(allocator, env, -1);
+		system_exit(env, -1);
 	}
 	return 0;
 }
@@ -163,4 +163,33 @@
 						"\n\t\t\t Default log level is 4(debug).\n");
     fprintf(stdout, "\t-f LOG_FILE\t set log file to LOG_FILE. Default is /dev/stderr\n");
     fprintf(stdout, " Help :\n\t-h \t display this help screen.\n\n");
+}
+
+/**
+ * Signal handler
+ */
+void sig_handler(int signal)
+{
+	switch(signal)
+	{
+		case SIGINT : 
+		{
+			AXIS2_LOG_INFO(system_env->log, "Received signal SIGINT. Server "
+						"shutting down");
+			axis2_http_server_stop(server, &system_env);
+			AXIS2_LOG_INFO(system_env->log, "Shutdown complete ...");
+			system_exit(system_env, 0);			
+		}
+		case SIGPIPE :
+		{
+			AXIS2_LOG_INFO(system_env->log, "Received signal SIGPIPE.  Client "
+						"request serve aborted");
+			return;
+		}
+		case SIGSEGV :
+		{
+			fprintf(stderr, "Received deadly signal SIGSEGV. Terminating\n");
+			_exit(-1);
+		}
+	}
 }