overlapped-io

Using overlapped IO for console input?

独自空忆成欢 提交于 2020-01-20 05:03:45
问题 I'm attempting to use overlapped IO to read input from the console by opening CONIN$ with the FILE_FLAG_OVERLAPPED flag. However, ReadFile blocks when I use it, even with an OVERLAPPED parameter. I've read some posts reporting that this is a Windows 7 bug. I am using 7 so that could be possible. Here's the code I'm using: // Create a console window AllocConsole(); AttachConsole(GetProcessId(GetModuleHandle(NULL))); HANDLE overlappedConsoleIn = CreateFile(L"CONIN$", GENERIC_READ, FILE_SHARE

Using overlapped IO for console input?

佐手、 提交于 2020-01-20 05:03:25
问题 I'm attempting to use overlapped IO to read input from the console by opening CONIN$ with the FILE_FLAG_OVERLAPPED flag. However, ReadFile blocks when I use it, even with an OVERLAPPED parameter. I've read some posts reporting that this is a Windows 7 bug. I am using 7 so that could be possible. Here's the code I'm using: // Create a console window AllocConsole(); AttachConsole(GetProcessId(GetModuleHandle(NULL))); HANDLE overlappedConsoleIn = CreateFile(L"CONIN$", GENERIC_READ, FILE_SHARE

Explanation for tiny reads (overlapped, buffered) outperforming large contiguous reads?

孤人 提交于 2019-12-28 05:10:30
问题 (apologies for the somewhat lengthy intro) During development of an application which prefaults an entire large file (>400MB) into the buffer cache for speeding up the actual run later, I tested whether reading 4MB at a time still had any noticeable benefits over reading only 1MB chunks at a time. Surprisingly, the smaller requests actually turned out to be faster. This seemed counter-intuitive, so I ran a more extensive test. The buffer cache was purged before running the tests (just for

Serial port and handling errors during overlapped I/O operations

五迷三道 提交于 2019-12-24 07:07:55
问题 I've been doing serial communications lately so I prepared a class being a simple interface to all those Windows API functions responsible for reading, writing, etc. All I/O operations inside this class are handled asynchronously. Before I go to my question, let me show you how I write and read data from serial port (this is only the reading function, because the structure of the writing one is exactly the same so there is no point in presenting both of them). function TSerialPort.Read(var

Error with ReadFile and Overlapped

拥有回忆 提交于 2019-12-23 02:52:07
问题 I have a problem with ReadFile and overlapped. first I use ReadFile with overlapped with 0 ZeroMemory(&overlapped ,sizeof(OVERLAPPED)); hDevice = CreateFileW(zwpath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL); if(hDevice != INVALID_HANDLE_VALUE){ ret = ReadFile(hDevice, buff, 1024, &numerobyte, &overlapped); } with a for(), I can see the bytes using a printf() for (int n=0; n<sizeof(buff); n++) {

storage and management of overlapped structure in multithreaded IOCP server

柔情痞子 提交于 2019-12-23 00:52:12
问题 Is it good idea to use LINKED LIST to store overlapped structure? my overlapped structure looks like this typedef struct _PER_IO_CONTEXT { WSAOVERLAPPED Overlapped; WSABUF wsabuf; .... some other per operation data .... struct _PER_IO_CONTEXT *pOverlappedForward; struct _PER_IO_CONTEXT *pOverlappedBack; } PER_IO_CONTEXT, *PPER_IO_CONTEXT; When iocp server starts i allocate (for example) 5000 of them in Linked List. The start of this list is stored in global variable PPER_IO_CONTEXT OvlList. I

Timer that supports overlapped I/O (for IOCP)?

我的梦境 提交于 2019-12-21 16:17:29
问题 I need to add timers support in an application based on I/O Completion Ports (IOCP). I would like to avoid the use of a specific thread to manage timers. On Linux, you can create a timer that delivers expiration notifications via a file descriptor (see timerfd.h man), so it's great to use it for example with epoll if your application is based on epoll. On Windows, you can use "waitable timers" with an asynchronous procedure call (ACP) (see http://msdn.microsoft.com/en-us/library/ms686898(v=VS

ReadFileEx, variable length - a few questions

假如想象 提交于 2019-12-13 05:04:43
问题 I'm trying to read from stderr of a child process. The data is lines of text created with sprintf(stderr, "some debug info\n") . I'm using ReadFileE x with a completion routine. I don't know how many lines of text or how long each line will be. So, what do I put as the nNumberOfBytesToRead parameter? My guess is I put the max size of my buffer, which I will make 4k; although I don't know if that's an optimal size. I'm guessing that if the line written to stderr is shorter than 4k, the

Windows WriteFile blocks even with FILE_FLAG_OVERLAPPED

非 Y 不嫁゛ 提交于 2019-12-11 16:28:53
问题 I have the following code that creates a file using CreateFile with the FILE_FLAG_OVERLAPPED flag, and then calls WriteFile 100 times in a loop, passing in an OVERLAPPED structure uint64_t GetPreciseTickCount() { FILETIME fileTime; GetSystemTimePreciseAsFileTime(&fileTime); ULARGE_INTEGER large; large.LowPart = fileTime.dwLowDateTime; large.HighPart = fileTime.dwHighDateTime; return large.QuadPart; } uint64_t g_blockedTime = 0, g_waitTime = 0; int main() { auto hFile = CreateFile( L"test.dat"

Writing synchronously to a file opened with FILE_FLAG_OVERLAPPED

泪湿孤枕 提交于 2019-12-10 20:57:22
问题 I have opened a file using HANDLE handle= CreateFileW( fileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); The file handle is then used for asynchronous read operations: ReadFile(handle, buffer, 1, NULL, &overlapped); This works. However, I want to do a synchronous write now. WriteFile documentation states that If hFile was opened with FILE_FLAG_OVERLAPPED, the following conditions are in effect: • The lpOverlapped parameter must point to a valid and