From 74a299fd0844db03569381929b4d3e8851f1b578 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 2 Jan 2006 12:19:12 +0000 Subject: [PATCH] 1. sws now supports two new "commands" and 2. if built with CURL_SWS_FORK_ENABLED defined it forks for each new connection and thus can support any amount of connection clients (used for hiper tests and not for the standard plain curl test suite) --- tests/FILEFORMAT | 8 +++-- tests/server/sws.c | 77 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT index e862f90c8..caaaf1986 100644 --- a/tests/FILEFORMAT +++ b/tests/FILEFORMAT @@ -83,9 +83,11 @@ NOSAVE SLOWDOWN PASVBADIP - makes PASV send back an illegal IP in its 227 response -For HTTP, one specified command is supported: - "auth_required" - if this is set and a POST/PUT is made without auth, the - server will NOT wait for the full request body to get sent +For HTTP: +auth_required - if this is set and a POST/PUT is made without auth, the + server will NOT wait for the full request body to get sent +idle - do nothing after receiving the request, just "sit idle" +stream - continuously send data to the client, never-ending diff --git a/tests/server/sws.c b/tests/server/sws.c index 5a2a15574..270c6a3af 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -66,6 +66,13 @@ /* include memdebug.h last */ #include "memdebug.h" +/* + * The normal sws build for the plain standard curl test suite has no use for + * fork(), but if you feel wild and crazy and want to setup some more exotic + * tests. Define this and run... + */ +/*#define CURL_SWS_FORK_ENABLED 1 */ + #define REQBUFSIZ 150000 #define REQBUFSIZ_TXT "149999" @@ -75,6 +82,10 @@ bool prevbounce; /* instructs the server to increase the part number for a test in case the identical testno+partno request shows up again */ +#define RCMD_NORMALREQ 0 /* default request, use the tests file normally */ +#define RCMD_IDLE 1 /* told to sit idle */ +#define RCMD_STREAM 2 /* told to stream */ + struct httprequest { char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */ int offset; /* size of the incoming request */ @@ -87,6 +98,8 @@ struct httprequest { size_t cl; /* Content-Length of the incoming request */ bool digest; /* Authorization digest header found */ bool ntlm; /* Authorization ntlm header found */ + + int rcmd; /* doing a special command, see defines above */ }; int ProcessRequest(struct httprequest *req); @@ -113,6 +126,13 @@ const char *serverlogfile = DEFAULT_LOGFILE; #define CMD_AUTH_REQUIRED "auth_required" +/* 'idle' means that it will accept the request fine but never respond + any data. Just keep the connection alive. */ +#define CMD_IDLE "idle" + +/* 'stream' means to send a never-ending stream of data */ +#define CMD_STREAM "stream" + #define END_OF_HEADERS "\r\n\r\n" enum { @@ -256,6 +276,15 @@ int ProcessRequest(struct httprequest *req) logmsg("instructed to require authorization header"); req->auth_req = TRUE; } + else if(!strncmp(CMD_IDLE, cmd, strlen(CMD_IDLE))) { + logmsg("instructed to idle"); + req->rcmd = RCMD_IDLE; + req->open = TRUE; + } + else if(!strncmp(CMD_STREAM, cmd, strlen(CMD_STREAM))) { + logmsg("instructed to stream"); + req->rcmd = RCMD_STREAM; + } free(cmd); } } @@ -356,7 +385,7 @@ int ProcessRequest(struct httprequest *req) /* If the client is passing this type-3 NTLM header */ req->partno += 1002; req->ntlm = TRUE; /* NTLM found */ - logmsg("Received NTLM type-3, xxxxxxxxxxxxx sending back data %d", req->partno); + logmsg("Received NTLM type-3, sending back data %d", req->partno); if(req->cl) { logmsg(" Expecting %d POSTed bytes", req->cl); } @@ -478,10 +507,30 @@ static int send_doc(int sock, struct httprequest *req) char partbuf[80]="data"; - req->open = FALSE; - logmsg("Send response number %d part %d", req->testno, req->partno); + switch(req->rcmd) { + default: + case RCMD_NORMALREQ: + break; /* continue with business as usual */ + case RCMD_STREAM: +#define STREAMTHIS "a string to stream 01234567890\n" + count = strlen(STREAMTHIS); + while(1) { + written = swrite(sock, STREAMTHIS, count); + if(written != (int)count) { + logmsg("Stopped streaming"); + return -1; + } + } + break; + case RCMD_IDLE: + /* Do nothing. Sit idle. Pretend it rains. */ + return 0; + } + + req->open = FALSE; + if(req->testno < 0) { switch(req->testno) { case DOCNUMBER_QUIT: @@ -752,9 +801,24 @@ int main(int argc, char *argv[]) while (1) { msgsock = accept(sock, NULL, NULL); - if (msgsock == -1) - continue; + if (msgsock == -1) { + printf("MAJOR ERROR: accept() failed!\n"); + break; + } +#ifdef CURL_SWS_FORK_ENABLED + /* 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; + } + + /* 0 is returned to the child */ + if(0 == rc) { +#endif logmsg("====> Client connect"); do { @@ -792,6 +856,9 @@ int main(int argc, char *argv[]) if (req.testno == DOCNUMBER_QUIT) break; +#ifdef CURL_SWS_FORK_ENABLED + } +#endif } sclose(sock);