12 SetLastError(NO_ERROR);
13 u.val32[0] = GetFileSize(p_handle,reinterpret_cast<DWORD*>(&u.val32[1]));
27 SetLastError(ERROR_SUCCESS);
28 temp_lo = SetFilePointer(p_handle,temp_lo,&temp_hi,(DWORD)p_mode);
34 ol.Offset = (DWORD)( s & 0xFFFFFFFF );
35 ol.OffsetHigh = (DWORD)(s >> 32);
40 if (inBytes == 0)
return;
45 SetLastError(NO_ERROR);
46 if (WriteFile( handle, in, inBytes, &bytesWritten, &ol)) {
48 if (bytesWritten != inBytes)
throw exception_io();
53 const DWORD code = GetLastError();
56 const HANDLE handles[] = {myEvent, abort.get_abort_event()};
57 SetLastError(NO_ERROR);
59 if (state == WAIT_OBJECT_0) {
61 WIN32_IO_OP( GetOverlappedResult(handle,&ol,&bytesWritten,TRUE) );
66 if (bytesWritten != inBytes)
throw exception_io();
70 throw exception_aborted();
74 const enum {writeMAX = 16*1024*1024};
76 while(done < inBytes) {
77 size_t delta = inBytes - done;
78 if (delta > writeMAX) delta = writeMAX;
79 writeOverlappedPass(handle, myEvent, position, (
const BYTE*)in + done, (DWORD) delta, abort);
85 const enum {writeMAX = 16*1024*1024};
87 while(done < inBytes) {
88 size_t delta = inBytes - done;
89 if (delta > writeMAX) delta = writeMAX;
97 if (outBytes == 0)
return 0;
102 SetLastError(NO_ERROR);
103 if (ReadFile( handle, out, outBytes, &bytesDone, &ol)) {
109 const DWORD code = GetLastError();
111 case ERROR_HANDLE_EOF:
112 case ERROR_BROKEN_PIPE:
114 case ERROR_IO_PENDING:
121 const HANDLE handles[] = {myEvent, abort.get_abort_event()};
122 SetLastError(NO_ERROR);
124 if (state == WAIT_OBJECT_0) {
125 SetLastError(NO_ERROR);
126 if (!GetOverlappedResult(handle,&ol,&bytesDone,TRUE)) {
127 const DWORD code = GetLastError();
128 if (code == ERROR_HANDLE_EOF || code == ERROR_BROKEN_PIPE) bytesDone = 0;
137 throw exception_aborted();
140 const enum {readMAX = 16*1024*1024};
142 while(done < outBytes) {
143 size_t delta = outBytes - done;
144 if (delta > readMAX) delta = readMAX;
145 delta =
readOverlappedPass(handle, myEvent, position, (BYTE*) out + done, (DWORD) delta, abort);
146 if (delta == 0)
break;
154 const enum {readMAX = 16*1024*1024};
156 while(done < outBytes) {
157 size_t delta = outBytes - done;
158 if (delta > readMAX) delta = readMAX;
159 delta =
readOverlappedPass(handle, myEvent, 0, (BYTE*) out + done, (DWORD) delta, abort);
160 if (delta == 0)
break;
192 return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
197 if (pCancelSynchronousIo == NULL) {
199 uDebugLog() <<
"Async CreateFile unavailable - using regular";
201 return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
204 uDebugLog() <<
"Starting async CreateFile...";
209 HANDLE waitHandles[2] = {hThread, abort.get_abort_event()};
213 case WAIT_OBJECT_0 + 1:
215 uDebugLog() <<
"Aborting async CreateFile...";
217 pCancelSynchronousIo(hThread);
223 CloseHandle(hThread);
228 if (abort.is_aborting()) {
229 if (data.
hResult != INVALID_HANDLE_VALUE) CloseHandle(data.
hResult);
230 throw exception_aborted();
t_filesize get_size(HANDLE p_handle)
DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE *lpHandles, BOOL bWaitAll, DWORD dwMilliseconds)
t_int64 t_sfilesize
Type used for file size related variables when a signed value is needed.
static unsigned CALLBACK createFileProc(void *data)
void seek(HANDLE p_handle, t_sfilesize p_position, file::t_seek_mode p_mode)
PFC_NORETURN void exception_io_from_win32(DWORD p_code)
typedef BOOL(WINAPI *pPowerSetRequest_t)(__in HANDLE PowerRequest
DWORD dwCreationDisposition
void fillOverlapped(OVERLAPPED &ol, HANDLE myEvent, t_filesize s)
void writeOverlapped(HANDLE handle, HANDLE myEvent, t_filesize &position, const void *in, size_t inBytes, abort_callback &abort)
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
DWORD readOverlappedPass(HANDLE handle, HANDLE myEvent, t_filesize position, void *out, DWORD outBytes, abort_callback &abort)
LPSECURITY_ATTRIBUTES lpSecurityAttributes
DWORD dwFlagsAndAttributes
t_uint64 t_filesize
Type used for file size related variables.
size_t readStreamOverlapped(HANDLE handle, HANDLE myEvent, void *out, size_t outBytes, abort_callback &abort)
size_t readOverlapped(HANDLE handle, HANDLE myEvent, t_filesize &position, void *out, size_t outBytes, abort_callback &abort)
HANDLE createFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile, abort_callback &abort)
BOOL(WINAPI * pCancelSynchronousIo_t)(HANDLE hThread)
PFC_NORETURN void SHARED_EXPORT uBugCheck()
void writeOverlappedPass(HANDLE handle, HANDLE myEvent, t_filesize position, const void *in, DWORD inBytes, abort_callback &abort)
void writeStreamOverlapped(HANDLE handle, HANDLE myEvent, const void *in, size_t inBytes, abort_callback &abort)