From 8d1239c091ef61725e6ce3c53b92b45a71f6f927 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Oct 2007 10:13:37 +0000 Subject: Disable the Nagle algorithm and send back responses in small chunks in an attempt to force smaller bits to get read by clients. --- tests/server/sws.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/server/sws.c b/tests/server/sws.c index edf42d098..1391bf93f 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -55,6 +55,9 @@ #ifdef HAVE_NETDB_H #include #endif +#ifdef HAVE_NETINET_TCP_H +#include /* for TCP_NODELAY */ +#endif #define ENABLE_CURLX_PRINTF /* make the curlx header define all printf() functions to use the curlx_* @@ -705,11 +708,20 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) responsesize = count; do { - written = swrite(sock, buffer, count); + /* Ok, we send no more than 200 bytes at a time, just to make sure that + larger chunks are split up so that the client will need to do multiple + recv() calls to get it and thus we exercise that code better */ + int num = count; + if(num > 200) + num = 200; + written = swrite(sock, buffer, num); if (written < 0) { logmsg("Sending response failed and we bailed out!"); return -1; } + else { + logmsg("Sent off %d bytes", written); + } /* write to file as well */ fwrite(buffer, 1, written, dump); @@ -776,6 +788,7 @@ int main(int argc, char *argv[]) #ifdef CURL_SWS_FORK_ENABLED bool use_fork = FALSE; #endif + int opt; while(argc>arg) { if(!strcmp("--version", argv[arg])) { @@ -938,7 +951,17 @@ int main(int argc, char *argv[]) #endif logmsg("====> Client connect"); - do { + /* + * Disable the Nagle algorithm to make it easier to send out a large + * response in many small segments to torture the clients more. + */ + opt = 1; + if (setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY, + (void *)&opt, sizeof(opt)) == -1) { + logmsg("====> TCP_NODELAY failed"); + } + + do { if(get_request(msgsock, &req)) /* non-zero means error, break out of loop */ break; -- cgit v1.2.3