Check-in [24f336c9ae]
Not logged in
Overview

SHA1 Hash:24f336c9ae5e3ea3fe292ea974a77cbd9f45a0d6
Date: 2008-05-17 17:52:08
User: drh
Comment:Make sure temporary files are well-named and are deleted after use in the win32 fossil server command.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/winhttp.c from [8692bfae97] to [c6afa8f76b].

@@ -39,10 +39,15 @@
   SOCKET s;           /* Socket on which to receive data */
   SOCKADDR_IN addr;   /* Address from which data is coming */
 };
 
 /*
+** Prefix for a temporary file.
+*/
+static char *zTempPrefix;
+
+/*
 ** Look at the HTTP header contained in zHdr.  Find the content
 ** length and return it.  Return 0 if there is no Content-Length:
 ** header line.
 */
 static int find_content_length(const char *zHdr){
@@ -70,12 +75,12 @@
   char zRequestFName[100];
   char zReplyFName[100];
   char zCmd[2000];          /* Command-line to process the request */
   char zHdr[2000];          /* The HTTP request header */
 
-  sprintf(zRequestFName, "win32_http_in%d.txt", p->id);
-  sprintf(zReplyFName, "win32_http_out%d.txt", p->id);
+  sprintf(zRequestFName, "%s_in%d.txt", zTempPrefix, p->id);
+  sprintf(zReplyFName, "%s_out%d.txt", zTempPrefix, p->id);
   amt = 0;
   while( amt<sizeof(zHdr) ){
     got = recv(p->s, &zHdr[amt], sizeof(zHdr)-1-amt, 0);
     if( got==SOCKET_ERROR ) goto end_request;
     if( got==0 ){
@@ -117,15 +122,15 @@
       send(p->s, zHdr, got, 0);
     }
   }
 
 end_request:
-  unlink(zRequestFName);
-  unlink(zReplyFName);
   if( out ) fclose(out);
   if( in ) fclose(in);
   closesocket(p->s);
+  unlink(zRequestFName);
+  unlink(zReplyFName);
   free(p);
 }
 
 /*
 ** Start a listening socket and process incoming HTTP requests on
@@ -138,11 +143,11 @@
   int idCnt = 0;
 
   if( WSAStartup(MAKEWORD(1,1), &wd) ){
     fossil_fatal("unable to initialize winsock");
   }
-
+  zTempPrefix = mprintf("fossil_server_P%d_", iPort);
   s = socket(AF_INET, SOCK_STREAM, 0);
   if( s==INVALID_SOCKET ){
     fossil_fatal("unable to create a socket");
   }
   addr.sin_family = AF_INET;