Newer
Older
msgsock = accept(sock, NULL, NULL);
printf("MAJOR ERROR: accept() failed with error: %d\n", SOCKERRNO);
break;
}
set_advisor_read_lock(SERVERLOGS_LOCK);
#ifdef CURL_SWS_FORK_ENABLED
Daniel Stenberg
committed
if(use_fork) {
/* The fork enabled version just forks off the child and don't care
about it anymore, so don't assume otherwise. Beware and don't do
this at home. */
rc = fork();
if(-1 == rc) {
printf("MAJOR ERROR: fork() failed!\n");
break;
}
Daniel Stenberg
committed
else
/* not a fork, just set rc so the following proceeds nicely */
rc = 0;
/* 0 is returned to the child */
if(0 == rc) {
#endif
#ifdef TCP_NODELAY
/*
* Disable the Nagle algorithm to make it easier to send out a large
* response in many small segments to torture the clients more.
*/
flag = 1;
if (setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
(void *)&flag, sizeof(flag)) == -1) {
logmsg("====> TCP_NODELAY failed");
}
/* 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 {
Daniel Stenberg
committed
if(get_request(msgsock, &req))
/* non-zero means error, break out of loop */
break;
Daniel Stenberg
committed
if(prevbounce) {
/* bounce treatment requested */
if((req.testno == prevtestno) &&
(req.partno == prevpartno)) {
req.partno++;
logmsg("BOUNCE part number to %ld", req.partno);
}
else {
prevbounce = FALSE;
prevtestno = -1;
prevpartno = -1;
}
Daniel Stenberg
committed
}
Daniel Stenberg
committed
send_doc(msgsock, &req);
Daniel Stenberg
committed
if((req.testno < 0) && (req.testno != DOCNUMBER_CONNECT)) {
logmsg("special request received, no persistency");
break;
}
Daniel Stenberg
committed
if(!req.open) {
logmsg("instructed to close connection after server-reply");
break;
}
Daniel Stenberg
committed
if(req.open)
logmsg("=> persistant connection request ended, awaits new request");
/* if we got a CONNECT, loop and get another request as well! */
Daniel Stenberg
committed
} while(req.open || (req.testno == DOCNUMBER_CONNECT));
sclose(msgsock);
clear_advisor_read_lock(SERVERLOGS_LOCK);
Daniel Stenberg
committed
if (req.testno == DOCNUMBER_QUIT)
break;
#ifdef CURL_SWS_FORK_ENABLED
}
#endif
sclose(sock);
clear_advisor_read_lock(SERVERLOGS_LOCK);