IOCP模型感悟

   搞了一段时间IOCP模型,发现IOCP就那三个函数,Create,GET,POST (分别对应 CreateIoCompletionPort ,GetQueuedCompletionStatus,PostQueuedCompletionStatus),无非就是一个队列,可以在线程中可以 Get,而无需枷锁。

最玄妙的要素是 其重叠结构  :

Delphi 中 Windows.pas 中声明如下

Type

 POverlapped = ^TOverlapped;
  _OVERLAPPED = record
    Internal: DWORD;
    InternalHigh: DWORD;
    Offset: DWORD;
    OffsetHigh: DWORD;
    hEvent: THandle;
  end;

  TOverlapped = _OVERLAPPED;
  OVERLAPPED = _OVERLAPPED;

 

可以在构造,如:

  TEventOverlapped = record
    Overlapped: Overlapped;
    pro: TThreadMethod;

    ....
    end;

 

看 Pro是在其 Overlapped 后面声明的 类型,当然可以根据实际情况进行 类型增加。在进行参数传递的时候,可以通过 POverlapped(EventOverlapped),形式进行传入。当然可以 POverlapped(EventOverlapped).Pro,进行处理数据。

 

 

 

 

你可能感兴趣的:(IOCP模型感悟)