你的位置:pcMing工作室 >> 资讯 >> 编程开发 >> C++编程 >> 详细内容 在线投稿

Winsock 完成端口模型简介

排行榜 收藏 打印 发给朋友 举报 来源: 互联网   发布者:未知
热度1217票  浏览421次 【共0条评论】【我要评论 时间:2010年4月08日 19:56
pcMing工作室j8? b|!L9_(U

$ynA ou0注:CreateIoCompletionPort ,PostQueuedCompletionStatus ,GetQueuedCompletionStatus 等函数的用法说明。

}S qT@&z$P;Ba0

'|c#L J!g0Platform SDK: Storage

7^\ D)m{o2b{.j5fiyc0 pcMing工作室c$i8ra9Tt

I/O Completion PortspcMing工作室1BoN:z-GB

pcMing工作室@Z'\}r

I/O completion ports are the mechanism by which an application uses a pool of threads that was created when the application was started to process asynchronous I/O requests. These threads are created for the sole purpose of processing I/O requests. Applications that process many concurrent asynchronous I/O requests can do so more quickly and efficiently by using I/O completion ports than by using creating threads at the time of the I/O request. pcMing工作室nk` E [ P:a_%kV

r})}Hxx0   pcMing工作室-C~2kf1X c(o)v~%?ZN)t

pcMing工作室%\2`,wy4`

I/O完成端口(s)是一种机制,通过这个机制,应用程序在启动时会首先创建一个线程池,然后该应用程序使用线程池处理异步I/O请求。这些线程被创建的唯一目的就是用于处理I/O请求。对于处理大量并发异步I/O请求的应用程序来说,相比于在I/O请求发生时创建线程来说,使用完成端口(s)它就可以做的更快且更有效率。

;wym,kb#mEs$Y0 pcMing工作室u*KC:M;m tw,_

  

V5B crmuGc(`0 pcMing工作室%J`8G5~;M"cj

The CreateIoCompletionPort function associates an I/O completion port with one or more file handles. When an asynchronous I/O operation started on a file handle associated with a completion port is completed, an I/O completion packet is queued to the port. This can be used to combine the synchronization point for multiple file handles into a single object. pcMing工作室{ oQu!v

pcMing工作室q-_1|;Um$QF:Jz,p^K \.c

   pcMing工作室a {m@6b"P

pcMing工作室Z X'F+yIFo,i;d

CreateIoCompletionPort函数会使一个I/O完成端口与一个或多个文件句柄发生关联。当与一个完成端口相关的文件句柄上启动的异步I/O操作完成时,一个I/O完成包就会进入到该完成端口的队列中。对于多个文件句柄来说,就可以把这些多个文件句柄合并成一个单独的对象,这个可以被用来结合同步点? pcMing工作室 t9q.d(Jp*~

pcMing工作室KG ] |&W8I

   pcMing工作室Q#iln:v8m$~5D

pcMing工作室$S(G,I!t|

A thread uses the GetQueuedCompletionStatus function to wait for a completion packet to be queued to the completion port, rather than waiting directly for the asynchronous I/O to complete. Threads that block their execution on a completion port are released in last-in-first-out (LIFO) order. This means that when a completion packet is queued to the completion port, the system releases the last thread to block its execution on the port.

%{"oB u6}8O A0 pcMing工作室VeXx"Z!j&oW t)g

调用 GetQueuedCompletionStatus函数,某个线程就会等待一个完成包进入到完成端口的队列中,而不是直接等待异步I/O请求完成。线程(们)就会阻塞于它们的运行在完成端口(按照后进先出队列顺序的被释放)。这就意味着当一个完成包进入到完成端口的队列中时,系统会释放最近被阻塞在该完成端口的线程。

2q"}!Fh`0

%WLX]8Q-@ rkV0   pcMing工作室B8c {jrJ}k

pcMing工作室)K&A)cd uBCsR-S

When a thread calls GetQueuedCompletionStatus, it is associated with the specified completion port until it exits, specifies a different completion port, or frees the completion port. A thread can be associated with at most one completion port.

2lq[0nB^[~0 pcMing工作室 l6j%k h}

调用GetQueuedCompletionStatus,线程就会将会与某个指定的完成端口建立联系,一直延续其该线程的存在周期,或被指定了不同的完成端口,或者释放了与完成端口的联系。一个线程只能与最多不超过一个的完成端口发生联系。

x.c ZBJ])HWo0 pcMing工作室6H-a0`%g y t M

   pcMing工作室3Nd)x3qo{8]

f `Xb)o:b0

顶:56 踩:65
对本文中的事件或人物打分:
当前平均分:-0.27 (371次打分)
对本篇资讯内容的质量打分:
当前平均分:-0.39 (350次打分)
【已经有375人表态】
59票
感动
46票
路过
54票
高兴
40票
难过
33票
搞笑
44票
愤怒
51票
无聊
48票
同情
上一篇 下一篇
发表评论
换一张

网友评论仅供网友表达个人看法,并不表明本网同意其观点或证实其描述。

查看全部回复【已有0位网友发表了看法】

网络资源