diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-12-01 16:58:45 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-12-01 19:38:30 +0900 |
| commit | 7e59e2dbb55649989102cccba96e56dbac4483ce (patch) | |
| tree | 138b79b3e254e63e1ddfeee28251a35889ad078f /src/AbstractDiskWriter.h | |
| parent | b95f15b462a0481d3197409eb1ac552d17e53fb6 (diff) | |
mingw32: Open file using _wsopen and added --enable-mmap support
I tried CreateFile but the subsequent ReadFile fails with Access
Denied if sparse file is read on NTFS. I mostly reverted previous
changes and use _wsopen with read/write share enabled instead of
CreateFile.
This change also includes --enable-mmap support for MinGW32
build. Memory mapped file may be useful for 64-bits OS and lots of
RAM. Currently, FlushViewOfFile is not called during the download, so
it is slightly vulnerable against sudden power loss. I found lots of
read when resuming download due to page fault. So for now it is useful
for the initial download. I recommend not to use
--file-allocation=prealloc with --enable-mmap for MinGW32, because it
triggers page faults even in the initial download. Anyway, the option
is experimental.
Diffstat (limited to 'src/AbstractDiskWriter.h')
| -rw-r--r-- | src/AbstractDiskWriter.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/AbstractDiskWriter.h b/src/AbstractDiskWriter.h index 282aaffd..34eabadd 100644 --- a/src/AbstractDiskWriter.h +++ b/src/AbstractDiskWriter.h @@ -44,15 +44,18 @@ class AbstractDiskWriter : public DiskWriter { private: std::string filename_; -#ifdef __MINGW32__ - HANDLE fd_; -#else // !__MINGW32__ int fd_; -#endif // !__MINGW32__ bool readOnly_; bool enableMmap_; +#ifdef __MINGW32__ + // This handle is retrieved from fd_ using _get_osfhandle(). It is + // used for Win32 API functions which only accept HANDLE. + HANDLE hn_; + // The handle for memory mapped file. mmap equivalent in Windows. + HANDLE mapView_; +#endif // __MINGW32__ unsigned char* mapaddr_; int64_t maplen_; |
