重叠IO
来源:互联网 发布:p2p理财安全吗 知乎 编辑:程序博客网 时间:2024/05/01 09:56
OVERLAPPED
The OVERLAPPED structure contains information used in asynchronous input and output (I/O).
typedef struct _OVERLAPPED { ULONG_PTR Internal; ULONG_PTR InternalHigh; DWORD Offset; DWORD OffsetHigh; HANDLE hEvent; } OVERLAPPED;
hEvent Handle to an event set to the signaled state when the operation has been completed. The calling process must set this member either to zero or a valid event handle before calling any overlapped functions. To create an event object, use the CreateEvent function. Functions such as WriteFile set the event to the nonsignaled state before they begin an I/O operation.
与重叠I\O操作关系最密切的是串口的读写操作,即ReadFile和WriteFile。
BOOL ReadFile( HANDLE hFile, // handle to file LPVOID lpBuffer, // data buffer DWORD nNumberOfBytesToRead, // number of bytes to read LPDWORD lpNumberOfBytesRead, // number of bytes read LPOVERLAPPED lpOverlapped // overlapped buffer);
在允许I\O重叠操作模式下,当ReadFile返回FALSE时并不代表读操作失败,GetLastError可能返回ERROR_IO_PENDING,即读操作还没有完成,但是函数立即返回.(在WinXP操作系统中有时会返回87, 待之后分析)。
Serial Communication Functions
Function | Description | CreateFileOpens a serial port.GetCommStateFills in a device-control block—DCB structure—with the current control settings for a specified communication device.SetCommStateConfigures a communication device according to the specifications in a DCB structure. The function reinitializes all hardware and control settings, but does not empty I/O queues.GetCommTimeoutsRetrieves the time-out parameters for all read/write operations on a specified communication device.SetCommTimeoutsSets the time-out parameters for all read/write operations on a specified communication device.WriteFileWrites data to a serial port, which transfers data to the device at the other end of a serial connection.ReadFileReads data from a serial port, which receives data from a device at the other end of a serial connection.SetCommMaskSpecifies a set of events to monitor for a communication device.GetCommMaskRetrieves the value of the event mask for a specified communication device.WaitCommEventWaits for an event to occur for a specified communication device. The set of events monitored by WaitCommEvent is contained in the event mask associated with the device handle.EscapeCommFunctionDirects a specified communication device to perform an extended function. Often used to set a serial port to IR mode.ClearCommBreakRestores character transmission for a specified communication device and places the transmission line in a non-break state.ClearCommErrorRetrieves communication error data and reports the current status of a specified communication device.