16 #if STXXL_HAVE_WINCALL_FILE
29 void wincall_file::serve(
const request* req)
throw (io_error)
31 scoped_mutex_lock fd_lock(fd_mutex);
32 assert(req->get_file() ==
this);
33 offset_type offset = req->get_offset();
34 void* buffer = req->get_buffer();
35 size_type
bytes = req->get_size();
36 request::request_type type = req->get_type();
38 if (bytes > 32 * 1024 * 1024) {
39 STXXL_ERRMSG(
"Using a block size larger than 32 MiB may not work with the " << io_type() <<
" filetype");
42 HANDLE handle = file_des;
43 LARGE_INTEGER desired_pos;
44 desired_pos.QuadPart = offset;
45 if (!SetFilePointerEx(handle, desired_pos, NULL, FILE_BEGIN))
48 "SetFilePointerEx in wincall_request::serve()" <<
49 " offset=" << offset <<
51 " buffer=" << buffer <<
53 " type=" << ((type == request::READ) ?
"READ" :
"WRITE"));
57 stats::scoped_read_write_timer read_write_timer(bytes, type == request::WRITE);
59 if (type == request::READ)
61 DWORD NumberOfBytesRead = 0;
63 if (!ReadFile(handle, buffer, (DWORD)bytes, &NumberOfBytesRead, NULL))
68 " offset=" << offset <<
69 " buffer=" << buffer <<
71 " type=" << ((type == request::READ) ?
"READ" :
"WRITE") <<
72 " NumberOfBytesRead= " << NumberOfBytesRead);
74 else if (NumberOfBytesRead != bytes) {
75 STXXL_THROW_WIN_LASTERROR(io_error,
" partial read: missing " << (bytes - NumberOfBytesRead) <<
" out of " << bytes <<
" bytes");
80 DWORD NumberOfBytesWritten = 0;
82 if (!WriteFile(handle, buffer, (DWORD)bytes, &NumberOfBytesWritten, NULL))
87 " offset=" << offset <<
88 " buffer=" << buffer <<
90 " type=" << ((type == request::READ) ?
"READ" :
"WRITE") <<
91 " NumberOfBytesWritten= " << NumberOfBytesWritten);
93 else if (NumberOfBytesWritten != bytes) {
94 STXXL_THROW_WIN_LASTERROR(io_error,
" partial write: missing " << (bytes - NumberOfBytesWritten) <<
" out of " << bytes <<
" bytes");
100 const char* wincall_file::io_type()
const
107 #endif // #if STXXL_HAVE_WINCALL_FILE
static const int bytes
number of bytes in uint_pair
#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
#define STXXL_END_NAMESPACE