1.2a and trunk-20060103, cygwin, win2K. Using libevent
as an http server does not always work when client is
sending its stuff in small packets.

Testcase: use notepad->clipboard->telnet, with the
following request:

POST /xyz.php HTTP/1.0
Host: 127.0.0.1
User-Agent: Mozilla/4.0
Accept: */*
Pragma: no-cache
Cache-Control: no-cache
Content-Type: application/octet-stream
Content-Length: 65
Connection: close

1qwertyuiop
2qwertyuiop
3qwertyuiop
4qwertyuiop
5qwertyuiop

Most times the handler registered with evhttp_set_cb()
is called with just one or two lines as payload.

char buf[200+1];
void cb(struct evhttp_request *req, void *arg) {
 int len = evbuffer_remove(req->input_buffer, buffer,
sizeof(buffer)-1);
 buffer[len] = 0;
 fprintf(stderr, "got %d bytes {%s}\n", len,
printable(buffer).Buffer()); }

sample output: "got 23 bytes
{1qwertyuiop[13][10]2qwertyuio}"

Tracing:

evhttp_get_body_length()
 enters the last else (content_length != NULL)
 req->ntoread = strtol(...) is 65

evhttp_get_body()
  req->ntoread == 65
  EVBUFFER_LENGTH(evcon->input_buffer) == 42
  if (req->ntoread > 0)
    req->ntoread -=
EVBUFFER_LENGTH(evcon->input_buffer);
  ^^^ now req->ntoread = 23

evhttp_read()
  ...
  n = evbuffer_read(buf, fd, -1);
  len = EVBUFFER_LENGTH(buf);
  event_debug(("%s: got %d on %d; len=%d
req->ntoread=%d\n", __func__, n, fd, len,
req->ntoread));
  prints: [debug] evhttp_read: got 23 on 6; len=65
req->ntoread=23
  ...
  } else if (len >= req->ntoread) {
    /* Completed content length */
  ^^^ oops. not really.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to