[Opensrf-commits] r1210 - in trunk: include/opensrf src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jan 6 21:36:00 EST 2008


Author: miker
Date: 2008-01-06 21:11:47 -0500 (Sun, 06 Jan 2008)
New Revision: 1210

Modified:
   trunk/include/opensrf/osrf_prefork.h
   trunk/src/libopensrf/osrf_prefork.c
Log:
Patch from Scott McKellar:

1. I moved almost everything from the header file into the
implementation file, since it isn't referenced elsewhere.  All that's
left is one function prototype and a series of nested #includes.

2. I added compilation guards to the header.

3. Except for osrf_prefork_run(), all functions are now static, as is
the child_dead variable.

4. I commented out the MAX_BUFSIZE macro, since it isn't used.

5. I removed the declaration of main(), which seemed rather pointless.

6. I added the const qualifier to the parameters of osrf_prefork_run()
and osrf_prefork_routers().

7. I made sure that all members were explicitly initialized when
creating a prefork_simple or a prefork_child.

8. I commented out both the prototype and the definition of
find_prefork_child(), since we don't call it anywhere.



Modified: trunk/include/opensrf/osrf_prefork.h
===================================================================
--- trunk/include/opensrf/osrf_prefork.h	2008-01-07 02:08:10 UTC (rev 1209)
+++ trunk/include/opensrf/osrf_prefork.h	2008-01-07 02:11:47 UTC (rev 1210)
@@ -1,3 +1,6 @@
+#ifndef OSRF_PREFORK_H
+#define OSRF_PREFORK_H
+
 #include <sys/types.h>
 #include <sys/time.h>
 #include <unistd.h>
@@ -14,10 +17,6 @@
 #include <opensrf/osrf_settings.h>
 #include <opensrf/osrfConfig.h>
 
-//#define READ_BUFSIZE 4096
-#define READ_BUFSIZE 1024
-#define MAX_BUFSIZE 10485760 /* 10M enough? ;) */
-#define ABS_MAX_CHILDREN 256 
 
 /* we receive data.  we find the next child in
 	line that is available.  pass the data down that childs pipe and go
@@ -30,67 +29,6 @@
 	data to the parent to alert the parent that the child is again available 
 	*/
 
-struct prefork_simple_struct {
-	int max_requests;
-	int min_children;
-	int max_children;
-	int fd;
-	int data_to_child;
-	int data_to_parent;
-	int current_num_children;
-	int keepalive; /* keepalive time for stateful sessions */
-	char* appname;
-	struct prefork_child_struct* first_child;
-	transport_client* connection;
-};
-typedef struct prefork_simple_struct prefork_simple;
+int osrf_prefork_run(const char* appname);
 
-struct prefork_child_struct {
-	pid_t pid;
-	int read_data_fd;
-	int write_data_fd;
-	int read_status_fd;
-	int write_status_fd;
-	int min_children;
-	int available;
-	int max_requests;
-	char* appname;
-	int keepalive;
-	struct prefork_child_struct* next;
-};
-
-typedef struct prefork_child_struct prefork_child;
-
-int osrf_prefork_run(char* appname);
-
-prefork_simple*  prefork_simple_init( transport_client* client, 
-	int max_requests, int min_children, int max_children );
-
-prefork_child*  launch_child( prefork_simple* forker );
-void prefork_launch_children( prefork_simple* forker );
-
-void prefork_run(prefork_simple* forker);
-
-void add_prefork_child( prefork_simple* forker, prefork_child* child );
-prefork_child* find_prefork_child( prefork_simple* forker, pid_t pid );
-void del_prefork_child( prefork_simple* forker, pid_t pid );
-
-void check_children( prefork_simple* forker, int forever );
-
-void prefork_child_process_request(prefork_child*, char* data);
-int prefork_child_init_hook(prefork_child*);
-
-prefork_child* prefork_child_init( 
-		int max_requests, int read_data_fd, int write_data_fd, 
-		int read_status_fd, int write_status_fd );
-
-/* listens on the 'data_to_child' fd and wait for incoming data */
-void prefork_child_wait( prefork_child* child );
-
-int prefork_free( prefork_simple* );
-int prefork_child_free( prefork_child* );
-
-
-void osrf_prefork_register_routers( char* appname );
-
-void osrf_prefork_child_exit( prefork_child* );
+#endif

Modified: trunk/src/libopensrf/osrf_prefork.c
===================================================================
--- trunk/src/libopensrf/osrf_prefork.c	2008-01-07 02:08:10 UTC (rev 1209)
+++ trunk/src/libopensrf/osrf_prefork.c	2008-01-07 02:11:47 UTC (rev 1210)
@@ -3,14 +3,74 @@
 #include <opensrf/osrf_application.h>
 #include <signal.h>
 
+//#define READ_BUFSIZE 4096
+#define READ_BUFSIZE 1024
+//#define MAX_BUFSIZE 10485760 /* 10M enough? ;) */
+#define ABS_MAX_CHILDREN 256
+
+struct prefork_simple_struct {
+	int max_requests;
+	int min_children;
+	int max_children;
+	int fd;
+	int data_to_child;
+	int data_to_parent;
+	int current_num_children;
+	int keepalive; /* keepalive time for stateful sessions */
+	char* appname;
+	struct prefork_child_struct* first_child;
+	transport_client* connection;
+};
+typedef struct prefork_simple_struct prefork_simple;
+
+struct prefork_child_struct {
+	pid_t pid;
+	int read_data_fd;
+	int write_data_fd;
+	int read_status_fd;
+	int write_status_fd;
+	int min_children;
+	int available;
+	int max_requests;
+	char* appname;
+	int keepalive;
+	struct prefork_child_struct* next;
+};
+
+typedef struct prefork_child_struct prefork_child;
+
+static prefork_simple* prefork_simple_init( transport_client* client,
+	int max_requests, int min_children, int max_children );
+static prefork_child* launch_child( prefork_simple* forker );
+static void prefork_launch_children( prefork_simple* forker );
+static void prefork_run(prefork_simple* forker);
+static void add_prefork_child( prefork_simple* forker, prefork_child* child );
+
+//static prefork_child* find_prefork_child( prefork_simple* forker, pid_t pid );
+
+static void del_prefork_child( prefork_simple* forker, pid_t pid );
+static void check_children( prefork_simple* forker, int forever );
+static void prefork_child_process_request(prefork_child*, char* data);
+static int prefork_child_init_hook(prefork_child*);
+static prefork_child* prefork_child_init(
+		int max_requests, int read_data_fd, int write_data_fd,
+		int read_status_fd, int write_status_fd );
+
+/* listens on the 'data_to_child' fd and wait for incoming data */
+static void prefork_child_wait( prefork_child* child );
+static int prefork_free( prefork_simple* );
+static int prefork_child_free( prefork_child* );
+static void osrf_prefork_register_routers( const char* appname );
+static void osrf_prefork_child_exit( prefork_child* );
+
+
 /* true if we just deleted a child.  This will allow us to make sure we're
 	not trying to use freed memory */
-int child_dead;
+static int child_dead;
 
-int main();
-void sigchld_handler( int sig );
+static void sigchld_handler( int sig );
 
-int osrf_prefork_run(char* appname) {
+int osrf_prefork_run(const char* appname) {
 
 	if(!appname) {
 		osrfLogError( OSRF_LOG_MARK, "osrf_prefork_run requires an appname to run!");
@@ -83,7 +143,7 @@
 
 }
 
-void osrf_prefork_register_routers( char* appname ) {
+static void osrf_prefork_register_routers( const char* appname ) {
 
 	osrfStringArray* arr = osrfNewStringArray(4);
 
@@ -113,7 +173,7 @@
 	osrfStringArrayFree(arr);
 }
 
-int prefork_child_init_hook(prefork_child* child) {
+static int prefork_child_init_hook(prefork_child* child) {
 
 	if(!child) return -1;
 	osrfLogDebug( OSRF_LOG_MARK, "Child init hook for child %d", child->pid);
@@ -149,7 +209,7 @@
 	return 0;
 }
 
-void prefork_child_process_request(prefork_child* child, char* data) {
+static void prefork_child_process_request(prefork_child* child, char* data) {
 	if( !child ) return;
 
 	transport_client* client = osrfSystemGetTransportClient();
@@ -220,7 +280,7 @@
 }
 
 
-prefork_simple*  prefork_simple_init( transport_client* client, 
+static prefork_simple*  prefork_simple_init( transport_client* client, 
 		int max_requests, int min_children, int max_children ) {
 
 	if( min_children > max_children ) {
@@ -243,13 +303,19 @@
 	prefork->max_requests = max_requests;
 	prefork->min_children = min_children;
 	prefork->max_children = max_children;
+	prefork->fd           = 0;
+	prefork->data_to_child = 0;
+	prefork->data_to_parent = 0;
+	prefork->current_num_children = 0;
+	prefork->keepalive    = 0;
+	prefork->appname      = NULL;
 	prefork->first_child = NULL;
 	prefork->connection = client;
 
 	return prefork;
 }
 
-prefork_child*  launch_child( prefork_simple* forker ) {
+static prefork_child* launch_child( prefork_simple* forker ) {
 
 	pid_t pid;
 	int data_fd[2];
@@ -315,12 +381,12 @@
 	return NULL;
 }
 
-void osrf_prefork_child_exit(prefork_child* child) {
+static void osrf_prefork_child_exit(prefork_child* child) {
    osrfAppRunExitCode();
    exit(0);
 }
 
-void prefork_launch_children( prefork_simple* forker ) {
+static void prefork_launch_children( prefork_simple* forker ) {
 	if(!forker) return;
 	int c = 0;
 	while( c++ < forker->min_children )
@@ -328,7 +394,7 @@
 }
 
 
-void sigchld_handler( int sig ) {
+static void sigchld_handler( int sig ) {
 	signal(SIGCHLD, sigchld_handler);
 	child_dead = 1;
 }
@@ -349,7 +415,7 @@
 	child_dead = 0;
 }
 
-void prefork_run(prefork_simple* forker) {
+static void prefork_run(prefork_simple* forker) {
 
 	if( forker->first_child == NULL )
 		return;
@@ -477,7 +543,7 @@
  * in the worst case it won't be slower and will do less logging...
  */
 
-void check_children( prefork_simple* forker, int forever ) {
+static void check_children( prefork_simple* forker, int forever ) {
 
 	//check_begin:
 
@@ -554,7 +620,7 @@
 }
 
 
-void prefork_child_wait( prefork_child* child ) {
+static void prefork_child_wait( prefork_child* child ) {
 
 	int i,n;
 	growing_buffer* gbuf = buffer_init( READ_BUFSIZE );
@@ -606,7 +672,7 @@
 }
 
 
-void add_prefork_child( prefork_simple* forker, prefork_child* child ) {
+static void add_prefork_child( prefork_simple* forker, prefork_child* child ) {
 	
 	if( forker->first_child == NULL ) {
 		forker->first_child = child;
@@ -634,21 +700,21 @@
 	return;
 }
 
-prefork_child* find_prefork_child( prefork_simple* forker, pid_t pid ) {
+//static prefork_child* find_prefork_child( prefork_simple* forker, pid_t pid ) {
+//
+//	if( forker->first_child == NULL ) { return NULL; }
+//	prefork_child* start_child = forker->first_child;
+//	do {
+//		if( forker->first_child->pid == pid ) 
+//			return forker->first_child;
+//	} while( (forker->first_child = forker->first_child->next) != start_child );
+//
+//	return NULL;
+//}
 
-	if( forker->first_child == NULL ) { return NULL; }
-	prefork_child* start_child = forker->first_child;
-	do {
-		if( forker->first_child->pid == pid ) 
-			return forker->first_child;
-	} while( (forker->first_child = forker->first_child->next) != start_child );
 
-	return NULL;
-}
+static void del_prefork_child( prefork_simple* forker, pid_t pid ) { 
 
-
-void del_prefork_child( prefork_simple* forker, pid_t pid ) { 
-
 	if( forker->first_child == NULL ) { return; }
 
 	(forker->current_num_children)--;
@@ -718,23 +784,28 @@
 
 
 
-prefork_child* prefork_child_init( 
+static prefork_child* prefork_child_init( 
 	int max_requests, int read_data_fd, int write_data_fd, 
 	int read_status_fd, int write_status_fd ) {
 
 	prefork_child* child = (prefork_child*) safe_malloc(sizeof(prefork_child));
+	child->pid              = 0;
 	child->max_requests		= max_requests;
 	child->read_data_fd		= read_data_fd;
 	child->write_data_fd		= write_data_fd;
 	child->read_status_fd	= read_status_fd;
 	child->write_status_fd	= write_status_fd;
+	child->min_children     = 0;
 	child->available			= 1;
+	child->appname          = NULL;
+	child->keepalive        = 0;
+	child->next             = NULL;
 
 	return child;
 }
 
 
-int prefork_free( prefork_simple* prefork ) {
+static int prefork_free( prefork_simple* prefork ) {
 	
 	while( prefork->first_child != NULL ) {
 		osrfLogInfo( OSRF_LOG_MARK,  "Killing children and sleeping 1 to reap..." );
@@ -748,7 +819,7 @@
 	return 1;
 }
 
-int prefork_child_free( prefork_child* child ) { 
+static int prefork_child_free( prefork_child* child ) { 
 	free(child->appname);
 	close(child->read_data_fd);
 	close(child->write_status_fd);



More information about the opensrf-commits mailing list