Mailing List Archive

r144 - cherokee/cherokee
Author: alo
Date: 2006-01-15 22:13:48 +0100 (Sun, 15 Jan 2006)
New Revision: 144

Modified:
cherokee/cherokee/fcgi_manager.c
cherokee/cherokee/fcgi_manager.h
cherokee/cherokee/handler_fastcgi.c
Log:


Modified: cherokee/cherokee/fcgi_manager.c
===================================================================
--- cherokee/cherokee/fcgi_manager.c 2006-01-15 20:10:59 UTC (rev 143)
+++ cherokee/cherokee/fcgi_manager.c 2006-01-15 21:13:48 UTC (rev 144)
@@ -128,6 +128,28 @@


static ret_t
+unregister_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn)
+{
+ cherokee_handler_fastcgi_t *fcgi;
+ cuint_t id;
+ cuint_t slot;
+
+ fcgi = FCGI(conn->handler);
+ id = fcgi->id;
+
+ if (id <= 0) {
+ return ret_error;
+ }
+
+ TRACE (ENTRIES, "Manager(%p) unregistered id=%d\n", fcgim, id);
+
+ slot = id - 1;
+ fcgim->conn_poll[slot] = NULL;
+ return ret_ok;
+}
+
+
+static ret_t
connect_to_srv (cherokee_fcgi_manager_t *fcgim)
{
ret_t ret;
@@ -158,83 +180,35 @@
}


-ret_t
-cherokee_fcgi_manager_connect_to_srv (cherokee_fcgi_manager_t *fcgim)
+static void
+connection_poll_clean (cherokee_fcgi_manager_t *fcgim)
{
- ret_t ret;
+ cherokee_connection_t *conn;
+ int i;

- LOCK;
- ret = connect_to_srv (fcgim);
- UNLOCK;
-
- return ret;
+ for (i=0; i<fcgim->conn_poll_size; i++) {
+ conn = fcgim->conn_poll [i];
+ if (conn != NULL)
+ unregister_conn (fcgim, conn);
+ }
}


static ret_t
-unregister_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn)
-{
- cherokee_handler_fastcgi_t *fcgi;
- cuint_t id;
- cuint_t slot;
-
- fcgi = FCGI(conn->handler);
- id = fcgi->id;
-
- if (id <= 0) {
- return ret_error;
- }
-
- TRACE (ENTRIES, "Manager(%p) unregistered id=%d\n", fcgim, id);
-
- slot = id - 1;
- fcgim->conn_poll[slot] = NULL;
- return ret_ok;
-}
-
-
-ret_t
-cherokee_fcgi_manager_unregister_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn)
-{
- ret_t ret;
-
- LOCK;
- ret = unregister_conn (fcgim, conn);
- UNLOCK;
-
- return ret;
-}
-
-
-static void
reset_connections (cherokee_fcgi_manager_t *fcgim)
{
- cherokee_connection_t *conn;
- int i;
-
/* The LOCK must be set when this function is called. It uses
* internal functions rather than public functions.
*/
-
TRACE (ENTRIES, "Manager(%p) reset connections (poll size: %d)\n", fcgim, fcgim->conn_poll_size);

- for (i=0; i<fcgim->conn_poll_size; i++) {
- conn = fcgim->conn_poll [i];
-/* if (conn != NULL) { */
-/* fcgi = (cherokee_handler_fastcgi_t *) conn->handler; */
-/* fcgi->status = fcgi_error; */
-/* } */
-
- if (conn != NULL)
- unregister_conn (fcgim, conn);
- }
-
- connect_to_srv (fcgim);
+ connection_poll_clean (fcgim);
+ return connect_to_srv (fcgim);
}


-ret_t
-cherokee_fcgi_manager_spawn_srv (cherokee_fcgi_manager_t *fcgim)
+static ret_t
+spawn_new_srv (cherokee_fcgi_manager_t *fcgim)
{
int re;
int child;
@@ -253,8 +227,6 @@

/* Execute the FastCGI server
*/
- LOCK;
-
cherokee_buffer_add_va (&tmp, "exec %s", fcgim->configuration_ref->interpreter.buf);

TRACE (ENTRIES, "Manager(%p) Launching: \"/bin/sh %s\"\n", fcgim, fcgim->configuration_ref->interpreter.buf);
@@ -280,19 +252,66 @@
}

cherokee_buffer_mrproper (&tmp);
-
- UNLOCK;
return ret_ok;

error:
cherokee_buffer_mrproper (&tmp);
+ return ret_error;
+}

+
+ret_t
+cherokee_fcgi_manager_spawn_connect (cherokee_fcgi_manager_t *fcgim)
+{
+ ret_t ret;
+
+ LOCK;
+
+ /* Try to connect..
+ */
+ ret = connect_to_srv (fcgim);
+ if (ret == ret_ok) {
+ UNLOCK;
+ return ret_ok;
+ }
+
+ /* If it couldn't connect, spawn a new server
+ */
+ ret = spawn_new_srv (fcgim);
+ if (unlikely (ret != ret_ok))
+ goto error;
+
+ /* Try to connect again
+ */
+ ret = connect_to_srv (fcgim);
+ if (unlikely (ret != ret_ok))
+ goto error;
+
+
UNLOCK;
+ return ret_ok;
+
+error:
+ UNLOCK;
return ret_error;
}


+
ret_t
+cherokee_fcgi_manager_unregister_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn)
+{
+ ret_t ret;
+
+ LOCK;
+ ret = unregister_conn (fcgim, conn);
+ UNLOCK;
+
+ return ret;
+}
+
+
+ret_t
cherokee_fcgi_manager_register_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn, cuint_t *id)
{
cuint_t i;

Modified: cherokee/cherokee/fcgi_manager.h
===================================================================
--- cherokee/cherokee/fcgi_manager.h 2006-01-15 20:10:59 UTC (rev 143)
+++ cherokee/cherokee/fcgi_manager.h 2006-01-15 21:13:48 UTC (rev 144)
@@ -61,8 +61,7 @@
ret_t cherokee_fcgi_manager_new (cherokee_fcgi_manager_t **fcgim, cherokee_fcgi_server_t *fcgi);
ret_t cherokee_fcgi_manager_free (cherokee_fcgi_manager_t *fcgim);

-ret_t cherokee_fcgi_manager_connect_to_srv (cherokee_fcgi_manager_t *fcgim);
-ret_t cherokee_fcgi_manager_spawn_srv (cherokee_fcgi_manager_t *fcgim);
+ret_t cherokee_fcgi_manager_spawn_connect (cherokee_fcgi_manager_t *fcgim);

ret_t cherokee_fcgi_manager_register_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn, cuint_t *id);
ret_t cherokee_fcgi_manager_unregister_conn (cherokee_fcgi_manager_t *fcgim, cherokee_connection_t *conn);

Modified: cherokee/cherokee/handler_fastcgi.c
===================================================================
--- cherokee/cherokee/handler_fastcgi.c 2006-01-15 20:10:59 UTC (rev 143)
+++ cherokee/cherokee/handler_fastcgi.c 2006-01-15 21:13:48 UTC (rev 144)
@@ -406,37 +406,42 @@
}


-static ret_t
-manager_connect (cherokee_fcgi_manager_t *fcgim, cherokee_fcgi_server_t *conf)
-{
- ret_t ret;
+/* static ret_t */
+/* manager_connect (cherokee_fcgi_manager_t *fcgim, cherokee_fcgi_server_t *conf) */
+/* { */
+/* ret_t ret; */

- ret = cherokee_fcgi_manager_connect_to_srv (fcgim);
- if (unlikely (ret != ret_ok)) {
+/* ret = cherokee_fcgi_manager_connect_to_srv (fcgim); */
+/* if (unlikely (ret != ret_ok)) { */

- TRACE (ENTRIES, "Could not connect to \"%s\"\n", conf->host.buf);
+/* TRACE (ENTRIES, "Could not connect to \"%s\"\n", conf->host.buf); */

- if (cherokee_buffer_is_empty (&conf->interpreter))
- return ret_error;
-
- /* Spawn a new FastCGI server
- */
- ret = cherokee_fcgi_manager_spawn_srv (fcgim);
- if (unlikely (ret != ret_ok)) return ret_error;
+/* if (cherokee_buffer_is_empty (&conf->interpreter)) */
+/* return ret_error; */

- TRACE (ENTRIES, "Spawning \"%s\"\n", conf->interpreter.buf);
+/* /\* Maybe it is reusing a Fcgi manager object, clean it up */
+/* *\/ */
+/* ret = cherokee_fcgi_manager_clean (fcgim); */
+/* if (unlikely (ret != ret_ok)) return ret_error; */
+
+/* /\* Spawn a new FastCGI server */
+/* *\/ */
+/* ret = cherokee_fcgi_manager_spawn_srv (fcgim); */
+/* if (unlikely (ret != ret_ok)) return ret_error; */

- /* Try to connect again
- */
- ret = cherokee_fcgi_manager_connect_to_srv (fcgim);
- if (unlikely (ret != ret_ok)) {
- PRINT_ERROR ("Couldn't connect to FCGI server.\n");
- return ret_error;
- }
- }
+/* TRACE (ENTRIES, "Spawning \"%s\"\n", conf->interpreter.buf); */
+
+/* /\* Try to connect again */
+/* *\/ */
+/* ret = cherokee_fcgi_manager_connect_to_srv (fcgim); */
+/* if (unlikely (ret != ret_ok)) { */
+/* PRINT_ERROR ("Couldn't connect to FCGI server.\n"); */
+/* return ret_error; */
+/* } */
+/* } */

- return ret_ok;
-}
+/* return ret_ok; */
+/* } */


ret_t
@@ -474,7 +479,8 @@

/* Launch and connect to the server
*/
- ret = manager_connect (n, fcgi->configuration);
+// ret = manager_connect (n, fcgi->configuration);
+ ret = cherokee_fcgi_manager_spawn_connect (n);
if (ret != ret_ok) return ret;
}

@@ -743,7 +749,7 @@
/* It has sent the request, but it couldn't read..
* lets reset the server and try again
*/
- ret = manager_connect (fcgi->manager_ref, fcgi->configuration);
+ ret = cherokee_fcgi_manager_spawn_connect (fcgi->manager_ref);
if (ret != ret_ok) return ret;

/* Lets reinject the connection