Changeset 32710


Ignore:
Timestamp:
Jul 16, 2017, 1:47:26 PM (10 days ago)
Author:
brainslayer
Message:

change read handler. this is a try to avoid the empty request header responsble problem we see sometimes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/httpd/httpd.c

    r32610 r32710  
    591591        char *str;
    592592
    593         for (cnt = 0; cnt < 10; cnt++) {
    594                 str = wfgets(line, LINE_LEN, conn_fp);
    595                 if (strlen(line) > 0)
     593        char *buf = line;
     594        int lastread = 0;
     595        for (;;) {
     596
     597                int r = wfread(buf, LINE_LEN - lastread, 1, conn_fp);
     598                if (r < 0 && (errno == EINTR || errno == EAGAIN))
     599                        continue;
     600                if (r <= 0)
    596601                        break;
     602                buf += r;
     603                lastread += r;
     604                if (strstr(line, "\015\012\015\012") != (char *)0 || strstr(line, "\012\012") != (char *)0)
     605                        break;
    597606        }
    598607
    599608        if (!strlen(line)) {
    600                 send_error(conn_fp, 400, "Bad Request", (char *)0, "No request found.");
     609                send_error(conn_fp, 408, "Request Timeout", NULL, "No request appeared within a reasonable time period.");
    601610                goto out;
    602611        }
     
    628637        /* Parse the rest of the request headers. */
    629638
    630         while (wfgets(cur, line + LINE_LEN - cur, conn_fp) != 0)        //jimmy,https,8/4/2003
     639        while (cur < (line + LINE_LEN)) //jimmy,https,8/4/2003
    631640        {
    632641
     
    15021511                get_client_ip_mac(conn_fp);
    15031512
     1513#ifdef TCP_NOPUSH
     1514                /* Set the TCP_NOPUSH socket option, to try and avoid the 0.2 second
     1515                 ** delay between sending the headers and sending the data.  A better
     1516                 ** solution is writev() (as used in thttpd), or send the headers with
     1517                 ** send(MSG_MORE) (only available in Linux so far).
     1518                 */
     1519                r = 1;
     1520                (void)setsockopt(conn_fp->conn_fd, IPPROTO_TCP, TCP_NOPUSH, (void *)&r, sizeof(r));
     1521#endif                          /* TCP_NOPUSH */
     1522
    15041523#ifndef HAVE_MICRO
    15051524                pthread_mutex_lock(&httpd_mutex);
Note: See TracChangeset for help on using the changeset viewer.