Mohammad DAMT wrote:
>> > It would be wonderful to be able to localize the last packet
>> > rather than parsing all the buffer.. I will take a look at it.
>>
>> I have committed this change, and it seems to be working..
>>
>> http://www.0x50.org/bugs/changeset/128
>>
>> so, we don't need to parse the full buffer any longer :-)
>>
>
> I found sometimes the write_buffer is changed somewhere so the
> last_header is no longer valid. So even the pad is appended but the
> pad length is not filled in paddingLength. With this patch now it
> will work for "ab -c 1 -n 100".
>
> Using -c more than 1 or -n more than 100 is still failing, with
> another cause of problem which is being investigated now.
Mohammad, I have been working on this for a while, and you were
right, something weird was happening with the buffer.
I'm about to commit something similar to the following patch, but
without the print_header() function (it was just for debugging
purposes, there is no point in keeping it there).
The patch also simplifies the add_env_pair_with_id*() a little bit,
and fixes the incorrect pointer you detected: it prints headers like
this one keeping the FastCGI connection open:
=====
header->version = 1
header->type = 4
header->requestIdB1 = 0
header->requestIdB0 = 1
header->contentLengthB1 = 0
header->contentLengthB0 = 22
header->paddingLength = 5
=====
Index: cherokee/handler_fastcgi.c
===================================================================
--- cherokee/handler_fastcgi.c (revision 132)
+++ cherokee/handler_fastcgi.c (working copy)
@@ -151,82 +151,51 @@
}
-#if 0
-
static void
-fixup_padding (cherokee_buffer_t *buf, cuint_t id)
+print_header (FCGI_Header *header)
{
- char *byte, *end, *last_pad;
- char padding [8] = {0, 0, 0, 0, 0, 0, 0, 0};
- int length;
- int crafted_id [2];
- int pad;
-
- if (buf->len == 0)
- return;
-
- if ((buf->len % 8) == 0)
- return;
-
- byte = (char*) buf->buf;
- end = buf->buf + buf->len;
-
- crafted_id [0] = (cuchar_t) id;
- crafted_id [1] = (cuchar_t) (id >> 8) & 0xff;
-
- while (byte < end) {
- byte += 4;
-
- length = (*byte << 8);
- byte ++;
- length |= *byte;
- byte ++;
- length += *byte;
-
- last_pad = byte;
- byte ++;
- byte += (length + 1);
- }
-
- pad = 8 - (buf->len % 8);
- cherokee_buffer_ensure_size (buf, buf->len + pad);
-
- *last_pad = pad;
- cherokee_buffer_add (buf, padding, pad);
+ printf ("header->version = %d\n", header->version);
+ printf ("header->type = %d\n", header->type);
+ printf ("header->requestIdB1 = %d\n", header->requestIdB1);
+ printf ("header->requestIdB0 = %d\n", header->requestIdB0);
+ printf ("header->contentLengthB1 = %d\n", header->contentLengthB1);
+ printf ("header->contentLengthB0 = %d\n", header->contentLengthB0);
+ printf ("header->paddingLength = %d\n", header->paddingLength);
+ printf ("\n");
}
-#endif
static void
-fixup_padding (cherokee_buffer_t *buf, cuint_t id, FCGI_Header *last_header)
+fixup_padding (cherokee_buffer_t *buf, cuint_t id, cuint_t last_header_offset)
{
- cuint_t rest;
- cuint_t pad;
- char padding[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+ cuint_t rest;
+ cuint_t pad;
+ char padding[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+ FCGI_Header *last_header;
if (buf->len <= 0)
return;
- rest = buf->len % 8;
- pad = 8 - rest;
+ last_header = (FCGI_Header *) (buf->buf + last_header_offset);
+ rest = buf->len % 8;
+ pad = 8 - rest;
if (rest == 0)
return;
last_header->paddingLength = pad;
+ print_header (last_header);
+
cherokee_buffer_ensure_size (buf, buf->len + pad);
cherokee_buffer_add (buf, padding, pad);
}
-
-
static void
-add_env_pair_with_id_and_header_ref (cherokee_buffer_t *buf, cuint_t id,
- char *key, int key_len,
- char *val, int val_len,
- FCGI_Header **req_ref)
+add_env_pair_with_id (cherokee_buffer_t *buf, cuint_t id,
+ char *key, int key_len,
+ char *val, int val_len)
{
FCGI_BeginRequestRecord request;
int len;
@@ -237,10 +206,7 @@
fcgi_build_header (&request.header, FCGI_PARAMS, id, len, 0);
- if (req_ref != NULL)
- *req_ref = (FCGI_Header *) buf->buf + buf->len;
-
- cherokee_buffer_ensure_size (buf, buf->len + key_len + val_len +
sizeof(FCGI_Header));
+ cherokee_buffer_ensure_size (buf, buf->len + sizeof(FCGI_Header) +
key_len + val_len);
cherokee_buffer_add (buf, (void *)&request.header, sizeof(FCGI_Header));
if (key_len <= 127) {
@@ -267,15 +233,6 @@
static void
-add_env_pair_with_id (cherokee_buffer_t *buf, cuint_t id,
- char *key, int key_len,
- char *val, int val_len)
-{
- add_env_pair_with_id_and_header_ref (buf, id, key, key_len, val,
val_len, NULL);
-}
-
-
-static void
add_env_pair_2_params (void *params[2],
char *key, int key_len,
char *val, int val_len)
@@ -291,7 +248,7 @@
static void
-add_more_env (cherokee_handler_fastcgi_t *fcgi, cherokee_buffer_t *buf,
FCGI_Header **last_header)
+add_more_env (cherokee_handler_fastcgi_t *fcgi, cherokee_buffer_t *buf,
cuint_t *last_header_offset)
{
cherokee_connection_t *conn;
cherokee_buffer_t buffer = CHEROKEE_BUF_INIT;
@@ -349,11 +306,16 @@
FCGI_PATH_TRANSLATED_VAR, sizeof
(FCGI_PATH_TRANSLATED_VAR) - 1,
buffer.buf, buffer.len);
- add_env_pair_with_id_and_header_ref (buf, fcgi->id,
- FCGI_SCRIPT_NAME_VAR, sizeof
(FCGI_SCRIPT_NAME_VAR) - 1,
- conn->request.buf,
conn->request.len,
- last_header);
+ /* The last package has a special treatment, we need
+ * to now where the header begins to set the right padding
+ */
+ *last_header_offset = buf->len;
+
+ add_env_pair_with_id (buf, fcgi->id,
+ FCGI_SCRIPT_NAME_VAR, sizeof
(FCGI_SCRIPT_NAME_VAR) - 1,
+ conn->request.buf, conn->request.len);
+
cherokee_buffer_mrproper (&buffer);
}
@@ -364,10 +326,10 @@
ret_t ret;
FCGI_BeginRequestRecord request;
void *params[2];
+ cuint_t last_header_offset;
cherokee_buffer_t tmp = CHEROKEE_BUF_INIT;
cherokee_buffer_t write_tmp = CHEROKEE_BUF_INIT;
cherokee_connection_t *conn = HANDLER_CONN (fcgi);;
- FCGI_Header *last_header = NULL;
cherokee_connection_parse_args (conn);
@@ -388,8 +350,8 @@
ret = cherokee_cgi_build_basic_env (conn, (cherokee_cgi_set_env_pair_t)
add_env_pair_2_params, &tmp, params);
if (unlikely (ret != ret_ok)) return ret;
- add_more_env (fcgi, &write_tmp, &last_header);
- fixup_padding (&write_tmp, fcgi->id, last_header);
+ add_more_env (fcgi, &write_tmp, &last_header_offset);
+ fixup_padding (&write_tmp, fcgi->id, last_header_offset);
cherokee_buffer_add_buffer (&fcgi->write_buffer, &write_tmp);
--
Greetings, alo.
http://www.alobbs.com
_______________________________________________
Cherokee mailing list
[email protected]
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee