随笔 - 298  文章 - 377  trackbacks - 0
<2008年3月>
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345

常用链接

留言簿(34)

随笔分类

随笔档案

文章档案

相册

收藏夹

搜索

  •  

最新评论

阅读排行榜

评论排行榜

1、创建IOCP

ACE_WIN32_Proactor::ACE_WIN32_Proactor (size_t number_of_threads,

                                        int used_with_reactor_event_loop)

 : completion_port_ (0),

    // This *MUST* be 0, *NOT* ACE_INVALID_HANDLE !!!

    number_of_threads_ (static_cast<DWORD> (number_of_threads)),

    used_with_reactor_event_loop_ (used_with_reactor_event_loop)

{

 // Create the completion port.

 this->completion_port_ = ::CreateIoCompletionPort (INVALID_HANDLE_VALUE,

                                                     0,

                                                     0,

                                                     this->number_of_threads_);

//...

}

2、将一个句柄同完成端口关联到一起

int

ACE_WIN32_Proactor::register_handle (ACE_HANDLE handle,

                                     const void *completion_key)

{

#if defined (_MSC_VER) && (_MSC_VER < 1300)

 ULONG comp_key (reinterpret_cast<ULONG> (completion_key));

#else

  ULONG_PTR comp_key (reinterpret_cast<ULONG_PTR> (completion_key));

#endif

 

 // No locking is needed here as no state changes.

 ACE_HANDLE cp = ::CreateIoCompletionPort (handle,

                                            this->completion_port_,

                                            comp_key,

                                            this->number_of_threads_);

//...

}

 

 

 

3、投递一个(或多个)异步操作

4、在完成端口上等待

int

ACE_WIN32_Proactor::handle_events (unsigned long milli_seconds)

{

  ACE_OVERLAPPED *overlapped = 0;

  u_long bytes_transferred = 0;

#if defined (_MSC_VER) && (_MSC_VER < 1300)

  ULONG completion_key = 0;

#else

  ULONG_PTR completion_key = 0;

#endif

 

  // Get the next asynchronous operation that completes

  BOOL result = ::GetQueuedCompletionStatus (this->completion_port_,

                                             &bytes_transferred,

                                             &completion_key,

                                             &overlapped,

                                             milli_seconds);

//Check errors

 

//Execute the completion handler

    this->application_specific_code (asynch_result,

                                       static_cast<size_t> (bytes_transferred),

                                       (void *) completion_key,

                                       result_err);

  return 1;

}

 

 

posted on 2007-08-17 12:01 聂文龙 阅读(343) 评论(0)  编辑 收藏 引用 所属分类: net work

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理