16 #if STXXL_HAVE_WINCALL_FILE
28 void wincall_file::serve(
void* buffer, offset_type offset, size_type
bytes,
29 request::request_type type)
31 scoped_mutex_lock fd_lock(fd_mutex);
33 if (bytes > 32 * 1024 * 1024) {
34 STXXL_ERRMSG(
"Using a block size larger than 32 MiB may not work with the " << io_type() <<
" filetype");
37 HANDLE handle = file_des;
38 LARGE_INTEGER desired_pos;
39 desired_pos.QuadPart = offset;
40 if (!SetFilePointerEx(handle, desired_pos, NULL, FILE_BEGIN))
43 "SetFilePointerEx in wincall_request::serve()" <<
44 " offset=" << offset <<
46 " buffer=" << buffer <<
48 " type=" << ((type == request::READ) ?
"READ" :
"WRITE"));
52 stats::scoped_read_write_timer read_write_timer(bytes, type == request::WRITE);
54 if (type == request::READ)
56 DWORD NumberOfBytesRead = 0;
58 if (!ReadFile(handle, buffer, (DWORD)bytes, &NumberOfBytesRead, NULL))
63 " offset=" << offset <<
64 " buffer=" << buffer <<
66 " type=" << ((type == request::READ) ?
"READ" :
"WRITE") <<
67 " NumberOfBytesRead= " << NumberOfBytesRead);
69 else if (NumberOfBytesRead != bytes) {
70 STXXL_THROW_WIN_LASTERROR(io_error,
" partial read: missing " << (bytes - NumberOfBytesRead) <<
" out of " << bytes <<
" bytes");
75 DWORD NumberOfBytesWritten = 0;
77 if (!WriteFile(handle, buffer, (DWORD)bytes, &NumberOfBytesWritten, NULL))
82 " offset=" << offset <<
83 " buffer=" << buffer <<
85 " type=" << ((type == request::READ) ?
"READ" :
"WRITE") <<
86 " NumberOfBytesWritten= " << NumberOfBytesWritten);
88 else if (NumberOfBytesWritten != bytes) {
89 STXXL_THROW_WIN_LASTERROR(io_error,
" partial write: missing " << (bytes - NumberOfBytesWritten) <<
" out of " << bytes <<
" bytes");
95 const char* wincall_file::io_type()
const
102 #endif // #if STXXL_HAVE_WINCALL_FILE
#define STXXL_THROW_WIN_LASTERROR(exception_type, error_message)
Throws exception_type with "Error in [function] : [error_message] : [formatted GetLastError()]".
#define STXXL_BEGIN_NAMESPACE
static uint_pair max()
return an uint_pair instance containing the largest value possible
static const size_t bytes
number of bytes in uint_pair
#define STXXL_END_NAMESPACE