]> granicus.if.org Git - libevent/commitdiff
Implement regress_make_tempfile on win32 to test evbuffer_add_file
authorNick Mathewson <nickm@torproject.org>
Sat, 8 May 2010 18:49:59 +0000 (14:49 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 8 May 2010 20:14:20 +0000 (16:14 -0400)
(Conclusion: evbuffer_add_file is broken on win32, since it
uses recv on a file.)

test/regress_buffer.c
test/regress_main.c

index 291eee6e5389b9b6f27f7f6674e510bf0944e33f..fa24738e653fcb0edd70751a8514f6f88604a974 100644 (file)
@@ -583,7 +583,6 @@ test_evbuffer_reference(void *ptr)
        evbuffer_free(src);
 }
 
-#ifndef WIN32
 int _evbuffer_testing_use_sendfile(void);
 int _evbuffer_testing_use_mmap(void);
 int _evbuffer_testing_use_linear_file_access(void);
@@ -643,7 +642,6 @@ test_evbuffer_add_file(void *ptr)
        evutil_closesocket(pair[1]);
        evbuffer_free(src);
 }
-#endif
 
 #ifndef _EVENT_DISABLE_MM_REPLACEMENT
 static void *
@@ -1544,9 +1542,9 @@ struct testcase_t evbuffer_testcases[] = {
          (void*)"sendfile" },
        { "add_file_mmap", test_evbuffer_add_file, TT_FORK, &nil_setup,
          (void*)"mmap" },
+#endif
        { "add_file_linear", test_evbuffer_add_file, TT_FORK, &nil_setup,
          (void*)"linear" },
-#endif
 
        END_OF_TESTCASES
 };
index f9544b6c941fa0827f03afe796902c3d0be92dab..822ea80b14ebda40643cd27eb584b2e3fbe1876b 100644 (file)
@@ -28,6 +28,8 @@
 #ifdef WIN32
 #include <winsock2.h>
 #include <windows.h>
+#include <io.h>
+#include <fcntl.h>
 #endif
 
 #include "event-config.h"
@@ -43,7 +45,6 @@
 #include <sys/time.h>
 #endif
 #include <sys/queue.h>
-#include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
 #endif
@@ -125,8 +126,30 @@ regress_make_tmpfile(const void *data, size_t datalen)
        unlink(tmpfilename);
        return (fd);
 #else
-       /* we need a windows implementation here */
-       return (-1);
+       /* XXXX actually delete the file later */
+       char tmpfilepath[MAX_PATH];
+       char tmpfilename[MAX_PATH];
+       DWORD r, written;
+       int tries = 16;
+       HANDLE h;
+       r = GetTempPathA(MAX_PATH, tmpfilepath);
+       if (r > MAX_PATH || r == 0)
+               return (-1);
+       for (; tries > 0; --tries) {
+               r = GetTempFileNameA(tmpfilepath, "LIBEVENT", 0, tmpfilename);
+               if (r == 0)
+                       return (-1);
+               h = CreateFileA(tmpfilename, GENERIC_READ|GENERIC_WRITE,
+                   0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+               if (h != INVALID_HANDLE_VALUE)
+                       break;
+       }
+       if (tries == 0)
+               return (-1);
+       written = 0;
+       WriteFile(h, data, datalen, &written, NULL);
+       /* Closing the fd returned by this function will indeed close h. */
+       return _open_osfhandle((intptr_t)h,_O_RDONLY);
 #endif
 }