aboutsummaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2007-02-14 00:28:01 +0000
committerYang Tse <yangsita@gmail.com>2007-02-14 00:28:01 +0000
commit7033a1c072af505ceb94b73112ec87914935e3fa (patch)
tree63562f676998c1d1edd2e52a00bbce8194e3c78e /tests/server
parent4efa0d9f6800b12e3ecb7e0291bc80fa8d8aa610 (diff)
enhance HTTP server request input writing,
retrying upon EINTR errors.
Diffstat (limited to 'tests/server')
-rw-r--r--tests/server/sws.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/tests/server/sws.c b/tests/server/sws.c
index a2d81c709..34e5aa22f 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -451,19 +451,46 @@ int ProcessRequest(struct httprequest *req)
/* store the entire request in a file */
void storerequest(char *reqbuf)
{
+ int error;
+ ssize_t written;
+ ssize_t writeleft;
+ ssize_t totalsize;
FILE *dump;
- dump = fopen(REQUEST_DUMP, "ab"); /* b is for windows-preparing */
- if(dump) {
- size_t len = strlen(reqbuf);
- fwrite(reqbuf, 1, len, dump);
+ if (reqbuf == NULL)
+ return;
- fclose(dump);
- logmsg("Wrote request (%d bytes) input to " REQUEST_DUMP,
- (int)len);
+ totalsize = strlen(reqbuf);
+ if (totalsize == 0)
+ return;
+
+ do {
+ dump = fopen(REQUEST_DUMP, "ab");
+ } while ((dump == NULL) && ((error = errno) == EINTR));
+ if (dump == NULL) {
+ logmsg("Error opening file %s error: %d", REQUEST_DUMP, error);
+ logmsg("Failed to write request input to " REQUEST_DUMP);
+ return;
+ }
+
+ writeleft = totalsize;
+ do {
+ written = fwrite((void *) &reqbuf[totalsize-writeleft],
+ 1, (size_t)writeleft, dump);
+ if (written > 0)
+ writeleft -= written;
+ } while ((writeleft > 0) && ((error = errno) == EINTR));
+
+ fclose(dump); /* close it ASAP */
+
+ if (writeleft > 0) {
+ logmsg("Error writing file %s error: %d", REQUEST_DUMP, error);
+ logmsg("Wrote only (%d bytes) of (%d bytes) request input to %s",
+ totalsize-writeleft, totalsize, REQUEST_DUMP);
}
else {
- logmsg("Failed to write request input to " REQUEST_DUMP);
+ logmsg("Wrote request (%d bytes) input to " REQUEST_DUMP,
+ totalsize);
}
}