rfc - ``httpd'' patch

Ilan Aelion <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Dimoco
Message-ID <[email protected]>
Hi all, 

I encountered some problems using gwlib httpd features. In particular, gwlib 
will PANIC when the open file limit is exceeded, which is not acceptable for 
many applications. 

Here's a patch that seems to help. 

And here's the question: I've added a few retries with a sleep in between in 
put_port_request in http.c. 

* Is there really a point in retrying? 
* Is there really a point in sleeping?
* would it be better to just skip failed requests immediately without 
retrying?

Thanks,
Ilan




Index: gwlib/http.c
===================================================================
RCS file: /var/cvsroot/dsmsc/gwlib/http.c,v
retrieving revision 1.2
diff -u -r1.2 http.c
--- gwlib/http.c	27 Jan 2005 18:54:48 -0000	1.2
+++ gwlib/http.c	5 Mar 2005 19:55:32 -0000
@@ -1903,18 +1903,32 @@
 }
 
 
-static void port_put_request(HTTPClient *client)
+static int port_put_request(HTTPClient *client)
 {
     Octstr *key;
-    struct port *p;
+    struct port *p = NULL;
+    int retry = 100; /* give up after 5 sec */
+    int ret = 0;
 
     mutex_lock(port_mutex);
     key = port_key(client->port);
     p = dict_get(port_collection, key);
-    gw_assert(p != NULL);
-    list_produce(p->clients_with_requests, client);
     octstr_destroy(key);
+    while (p == NULL && retry--) {
+        warning(0, "HTTPClient: can\'t port_put_request, retrying in 50 
msec");
+        gwthread_sleep(0.050); /* sleep 50 msec before retry */
+        key = port_key(client->port);
+        p = dict_get(port_collection, key);
+        octstr_destroy(key);
+    }
+    if (p == NULL) {
+        error(0, "HTTPClient: can\'t port_put_request, skipping");
+        ret = -1;
+    } else {
+        list_produce(p->clients_with_requests, client);
+    }
     mutex_unlock(port_mutex);
+    return ret;
 }
 
 
@@ -2048,7 +2062,10 @@
 	    if (ret == 0) {
 	    	client->state = request_is_being_handled;
 		conn_unregister(conn);
-		port_put_request(client);
+		if ((ret = port_put_request(client))) {
+		    goto error;
+//                    client->state = reading_request_line;
+                }
 	    }
 	    return;
 
Index: gwlib/thread.c
===================================================================
RCS file: /var/cvsroot/dsmsc/gwlib/thread.c,v
retrieving revision 1.2
diff -u -r1.2 thread.c
--- gwlib/thread.c	27 Sep 2004 16:59:21 -0000	1.2
+++ gwlib/thread.c	5 Mar 2005 19:55:32 -0000
@@ -113,8 +113,13 @@
     }
 #endif
 
-    if ((ret = pthread_mutex_destroy(&mutex->mutex)) != 0)
-        panic(ret, "Attempt to destroy locked mutex!");
+    if ((ret = pthread_mutex_destroy(&mutex->mutex)) != 0) {
+        error(ret, "Attempt to destroy locked mutex!");
+	pthread_mutex_unlock(&mutex->mutex);
+	if ((ret = pthread_mutex_destroy(&mutex->mutex)) != 0) {
+            error(ret, "Mutex: mutex won't unlock, ignoring");
+	}
+    }
 
     if (mutex->dynamic == 0)
         return;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.