Mailing List Archive

r140 - in cherokee: . cherokee
Author: alo
Date: 2006-01-15 13:26:19 +0100 (Sun, 15 Jan 2006)
New Revision: 140

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


Modified: cherokee/ChangeLog
===================================================================
--- cherokee/ChangeLog 2006-01-14 17:07:02 UTC (rev 139)
+++ cherokee/ChangeLog 2006-01-15 12:26:19 UTC (rev 140)
@@ -1,3 +1,8 @@
+2006-01-15 Alvaro Lopez Ortega <alvaro at alobbs.com>
+
+ * cherokee/handler_fastcgi.c, cherokee/fcgi_manager.c, ,
+ cherokee/fcgi_manager.h: Some FastCGI fixes by Mohammad DAMT.
+
2006-01-13 Alvaro Lopez Ortega <alvaro at alobbs.com>

* cherokee/http.c (entry): There was a memory corruption problem

Modified: cherokee/cherokee/fcgi_manager.c
===================================================================
--- cherokee/cherokee/fcgi_manager.c 2006-01-14 17:07:02 UTC (rev 139)
+++ cherokee/cherokee/fcgi_manager.c 2006-01-15 12:26:19 UTC (rev 140)
@@ -34,7 +34,7 @@
#include <sys/types.h>
#include <unistd.h>

-#define ENTRIES "fastcgi"
+#define ENTRIES "fastcgi,fastcgi-manager"

#define DEFAULT_PORT 8002
#define CONN_POLL_INCREMENT 16
@@ -362,35 +362,36 @@
}


-/* static void */
-/* set_status (cherokee_fcgi_manager_t *fcgim, cherokee_fcgi_status_t status) */
-/* { */
-/* cherokee_handler_fastcgi_t *fcgi; */
-/* cherokee_connection_t *conn; */
-
-/* conn = fcgim->conn_poll [fcgim->request_id - 1]; */
-/* if (conn != NULL) { */
-/* fcgi = (cherokee_handler_fastcgi_t *) conn->handler; */
-/* if (fcgi != NULL) { */
-/* fcgi->status = status; */
-/* } */
-/* } */
-/* } */
+static cherokee_handler_fastcgi_t *
+get_handler_ref (cherokee_fcgi_manager_t *fcgim)
+{
+ cherokee_handler_fastcgi_t *fcgi = NULL;
+ cherokee_connection_t *conn;

+ conn = fcgim->conn_poll [fcgim->request_id - 1];
+ if (conn == NULL) {
+ SHOULDNT_HAPPEN;
+ return NULL;
+ }
+
+ fcgi = FCGI(conn->handler);
+ if (fcgi == NULL) {
+ SHOULDNT_HAPPEN;
+ return NULL;
+ }

+ return fcgi;
+}
+
+
static void
-process_buffer (cherokee_fcgi_manager_t *fcgim, void *data, cuint_t data_len)
+process_buffer (cherokee_fcgi_manager_t *fcgim, cherokee_handler_fastcgi_t *fcgi, void *data, cuint_t data_len)
{
- cherokee_connection_t *conn;
- cherokee_handler_fastcgi_t *fcgi;
- char *message;
+ cherokee_connection_t *conn;
+ char *message;

conn = fcgim->conn_poll [fcgim->request_id - 1];
- if (conn == NULL) return;

- fcgi = (cherokee_handler_fastcgi_t *) conn->handler;
- if (fcgi == NULL) return;
-
switch (fcgim->request_type) {
case FCGI_STDERR:
message = (char*) strndup (data, data_len + 1);
@@ -401,24 +402,27 @@

case FCGI_STDOUT:
cherokee_buffer_add (&fcgi->incoming_buffer, data, data_len);
-/* if (fcgim->remaining_size == 0) */
-/* set_status (fcgim, fcgi_data_available); */
break;
}
}


static ret_t
-process_read_buffer (cherokee_fcgi_manager_t *fcgim, cherokee_handler_fastcgi_t *fcgi)
+process_read_buffer (cherokee_fcgi_manager_t *fcgim)
{
- ret_t ret = ret_eagain;
- cuint_t len;
- cuint_t offset = 0;
- cuint_t bytes_to_move;
- FCGI_Header *header;
- FCGI_EndRequestBody *end_request;
- void *start = fcgim->read_buffer.buf;
+ ret_t ret;
+ cuint_t len;
+ cuint_t offset;
+ cuint_t bytes_to_move;

+ FCGI_Header *header;
+ FCGI_EndRequestBody *end_request;
+ void *start = fcgim->read_buffer.buf;
+ cherokee_handler_fastcgi_t *fcgi = NULL;
+
+ offset = 0;
+ ret = ret_eagain;
+
while (fcgim->read_buffer.len > 0)
{
if (fcgim->remaining_size == 0) {
@@ -480,11 +484,16 @@
}
}

+
+ fcgi = get_handler_ref (fcgim);
+ if (fcgi == NULL)
+ return ret_error;
+
switch (fcgim->request_type) {
case FCGI_STDERR:
case FCGI_STDOUT:
if (len > 0)
- process_buffer (fcgim, (start + offset), len);
+ process_buffer (fcgim, fcgi, (start + offset), len);
break;

case FCGI_END_REQUEST:
@@ -519,33 +528,15 @@


ret_t
-cherokee_fcgi_manager_step (cherokee_fcgi_manager_t *fcgim, cuint_t id)
+cherokee_fcgi_manager_step (cherokee_fcgi_manager_t *fcgim)
{
- ret_t ret;
- size_t size = 0;
- cherokee_connection_t *conn;
- cherokee_handler_fastcgi_t *fcgi;
+ ret_t ret;
+ size_t size = 0;

LOCK;

- conn = fcgim->conn_poll [id - 1];
- if (conn == NULL) {
- SHOULDNT_HAPPEN;
+ TRACE (ENTRIES, "Manager(%p) step in_buf.len=%d\n", fcgim, fcgim->read_buffer.len);

- UNLOCK;
- return ret_error;
- }
-
- fcgi = FCGI(conn->handler);
- if (conn == NULL) {
- SHOULDNT_HAPPEN;
-
- UNLOCK;
- return ret_error;
- }
-
- TRACE (ENTRIES, "Manager(%p) step id=%d, in_buf.len=%d\n", fcgim, id, fcgim->read_buffer.len);
-
/* Read from the FastCGI application
*/
if (fcgim->read_buffer.len < sizeof(FCGI_Header)) {
@@ -567,12 +558,12 @@
return ret_error;
}

- TRACE (ENTRIES, "Manager(%p) readed ID=%d ret=%d size=%d\n", fcgim, id, ret, size);
+ TRACE (ENTRIES, "Manager(%p) readed ret=%d size=%d\n", fcgim, ret, size);
}

/* Process the new chunk
*/
- ret = process_read_buffer (fcgim, fcgi);
+ ret = process_read_buffer (fcgim);
switch (ret) {
case ret_ok:
case ret_eagain:

Modified: cherokee/cherokee/fcgi_manager.h
===================================================================
--- cherokee/cherokee/fcgi_manager.h 2006-01-14 17:07:02 UTC (rev 139)
+++ cherokee/cherokee/fcgi_manager.h 2006-01-15 12:26:19 UTC (rev 140)
@@ -67,7 +67,7 @@
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);

-ret_t cherokee_fcgi_manager_step (cherokee_fcgi_manager_t *fcgim, cuint_t);
+ret_t cherokee_fcgi_manager_step (cherokee_fcgi_manager_t *fcgim);
ret_t cherokee_fcgi_manager_send (cherokee_fcgi_manager_t *fcgim, cherokee_buffer_t *info, size_t *sent);

#endif /* CHEROKEE_FCGI_MANAGER_H */

Modified: cherokee/cherokee/handler_fastcgi.c
===================================================================
--- cherokee/cherokee/handler_fastcgi.c 2006-01-14 17:07:02 UTC (rev 139)
+++ cherokee/cherokee/handler_fastcgi.c 2006-01-15 12:26:19 UTC (rev 140)
@@ -477,7 +477,7 @@

/* Read info from the FastCGI
*/
- return cherokee_fcgi_manager_step (fcgim, fcgi->id);
+ return cherokee_fcgi_manager_step (fcgim);
}


@@ -709,8 +709,11 @@
RET_UNKNOWN(ret);
}

- if (cherokee_buffer_is_empty (&fcgi->incoming_buffer))
+ if (cherokee_buffer_is_empty (&fcgi->incoming_buffer)) {
+ if (fcgi->phase != fcgi_phase_finished)
+ return ret_eagain;
return ret_error;
+ }

/* Look the end of headers
*/