OVERLAPPED structure学习

Contains information used in asynchronous (or overlapped) input and output (I/O).

包含用在异步输入和输入IO的信息。

定义:

typedef struct _OVERLAPPED {
  ULONG_PTR Internal;
  ULONG_PTR InternalHigh;
  union {
    struct {
      DWORD Offset;
      DWORD OffsetHigh;
    };
    PVOID  Pointer;
  };
  HANDLE    hEvent;
} OVERLAPPED, *LPOVERLAPPED;

Members

Internal

IO请求的状态码,当一个请求来了,操作系统设置将变量为STATUS_PENDING来暗示这个操作还没有开始。当请求完成了,设置为另一状态。

InternalHigh

为IO请求传输的字节数。

Offset

开始IO请求文件位置的低位部分。如果不是文件,那必须设为0.

OffsetHigh

高位部分

Pointer

内部调用,一般设为NULL。

hEvent

一个事件句柄将用来设置为激发态,当操作完成后。用户必须初始化这个句柄。这个event可以用来同步一个设备上并发的IO请求。

注意

Any unused members of this structure should always be initialized to zero before the structure is used in a function call. Otherwise, the function may fail and return ERROR_INVALID_PARAMETER.

结构中不用的成员应该被设置为0.

The Offset and OffsetHigh members together represent a 64-bit file position. It is a byte offset from the start of the file or file-like device, and it is specified by the user; the system will not modify these values. The calling process must set this member before passing the OVERLAPPED structure to functions that use an offset, such as the ReadFile or WriteFile(and related) functions.

You can use the HasOverlappedIoCompleted macro to check whether an asynchronous I/O operation has completed ifGetOverlappedResult is too cumbersome for your application.

You can use the CancelIo function to cancel an asynchronous I/O operation.

A common mistake is to reuse an OVERLAPPED structure before the previous asynchronous operation has been completed. You should use a separate structure for each request. You should also create an event object for each thread that processes data. If you store the event handles in an array, you could easily wait for all events to be signaled using the WaitForMultipleObjects function.

For additional information and potential pitfalls of asynchronous I/O usage, see CreateFileReadFileWriteFile, and related functions.

For a general synchronization overview and conceptual OVERLAPPED usage information, see Synchronization and Overlapped Input and Output and related topics.

For a file I/O–oriented overview of synchronous and asynchronous I/O, see Synchronous and Asynchronous I/O.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值