Commit cd63a461 authored by Yang Tse's avatar Yang Tse
Browse files

proper initialization of httprequest, no longer zeroing out twice

the whole 150000+ bytes struct, and also removing an equally big
additional buffer for pipelining treatment.
parent 7bd098f6
Loading
Loading
Loading
Loading
+24 −21
Original line number Diff line number Diff line
@@ -529,30 +529,37 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
  int fail= FALSE;
  char *reqbuf = req->reqbuf;

  char pipereq[REQBUFSIZ];
  int pipereq_length;
  char *pipereq;
  int pipereq_length = 0;

  if(req->pipelining) {
    pipereq = reqbuf + req->checkindex;
    pipereq_length = req->offset - req->checkindex;
    memcpy(pipereq, reqbuf + req->checkindex, pipereq_length);
  }
  else
    pipereq_length = 0;

  /*** Init the httpreqest structure properly for the upcoming request ***/
  memset(req, 0, sizeof(struct httprequest));

  /* here's what should not be 0 from the start */
  req->testno = DOCNUMBER_NOTHING; /* safe default */
  req->open = TRUE; /* connection should remain open and wait for more
                       commands */
  req->checkindex = 0;
  req->offset = 0;
  req->testno = DOCNUMBER_NOTHING;
  req->partno = 0;
  req->open = TRUE;
  req->auth_req = FALSE;
  req->auth = FALSE;
  req->cl = 0;
  req->digest = FALSE;
  req->ntlm = FALSE;
  req->pipe = 0;
  req->rcmd = RCMD_NORMALREQ;
  req->prot_version = 0;
  req->pipelining = FALSE;

  /*** end of httprequest init ***/

  while (req->offset < REQBUFSIZ) {
    ssize_t got;
    if(pipereq_length) {
      memcpy(reqbuf, pipereq, pipereq_length);
      memmove(reqbuf, pipereq, pipereq_length); 
      got = pipereq_length;
      pipereq_length = 0;
    }
@@ -1001,14 +1008,10 @@ int main(int argc, char *argv[])
    }
#endif

  /* full initialization for new request after connection */
  memset(&req, 0, sizeof(req));
  req.testno = DOCNUMBER_NOTHING;
  req.open = TRUE;
  req.auth_req = FALSE;
  req.auth = FALSE;
  req.digest = FALSE;
  req.ntlm = FALSE;
    /* initialization of httprequest struct is done in get_request(), but due
       to pipelining treatment the pipelining struct field must be initialized
       previously to FALSE every time a new connection arrives. */

    req.pipelining = FALSE;

    do {