void writeOverlappedPass(HANDLE handle, HANDLE myEvent, t_filesize position, const void * in,DWORD inBytes, abort_callback & abort) { abort.check(); if (inBytes == 0) return; OVERLAPPED ol = {}; fillOverlapped(ol, myEvent, position); ResetEvent(myEvent); DWORD bytesWritten; SetLastError(NO_ERROR); if (WriteFile( handle, in, inBytes, &bytesWritten, &ol)) { // succeeded already? if (bytesWritten != inBytes) throw exception_io(); return; } { const DWORD code = GetLastError(); if (code != ERROR_IO_PENDING) exception_io_from_win32(code); } const HANDLE handles[] = {myEvent, abort.get_abort_event()}; SetLastError(NO_ERROR); DWORD state = WaitForMultipleObjects(_countof(handles), handles, FALSE, INFINITE); if (state == WAIT_OBJECT_0) { try { WIN32_IO_OP( GetOverlappedResult(handle,&ol,&bytesWritten,TRUE) ); } catch(...) { CancelIo(handle); throw; } if (bytesWritten != inBytes) throw exception_io(); return; } CancelIo(handle); throw exception_aborted(); }
void create_path(const char * p_path,abort_callback & p_abort) { if (test_localpath(p_path)) { t_size walk = 0; if (pfc::strcmp_partial(p_path,"file://") == 0) walk += strlen("file://"); create_path_internal(p_path,walk + 3,p_abort); } else if (test_netpath(p_path)) { t_size walk = 0; if (pfc::strcmp_partial(p_path,"file://") == 0) walk += strlen("file://"); while(p_path[walk] == '\\') walk++; while(p_path[walk] != 0 && p_path[walk] != '\\') walk++; while(p_path[walk] == '\\') walk++; create_path_internal(p_path,walk,p_abort); } else { throw exception_io("Could not create directory structure; unknown path format"); } }