开发者

Is is possible to use IOCP (or other API) in Reactor-style operations?

开发者 https://www.devze.com 2022-12-25 08:06 出处:网络
Is there any scalable Win32 API (like IOCP not like select) that gives you reactor style operations on so开发者_高级运维ckets? AFAIK IOCP allows you to receive notification on completed operations

Is there any scalable Win32 API (like IOCP not like select) that gives you reactor style operations on so开发者_高级运维ckets? AFAIK IOCP allows you to receive notification on completed operations like data read or written (proactor) but I'm looking for reactor style of operations: I need to get notification when the socket is readable or writable (reactor).

Something similar to epoll, kqueue, /dev/poll ?

Is there such API in Win32? If so where can I find a manual on it?

** Clarification:** I need select like api for sockets that is as scalable as IOCP, or I'm looking for a way to use IOCP in reactor like operations.

Even more clarification: IOCP allows you to receive an notification on completion of given operation. For example:

WSARecv(buffer,...); // start reading
WSAWaitForMultipleEvents(...); // wait when read is done

So I get notication after operation is done -- proctor style of operations.

What I need is something like that:

WSARecv( NOTHING ); // start waiting for readability (not actual read)
WSAWaitForMultipleEvents(...); // wait until read would not block
// Now WSARecv would not block
WSARecv(buffer,...); // now actual non-blocking read

How can I do this?


You want to look at the WSAAsyncSelect API. It uses a Windows message queue to signal that a handle is read for read/write/whatever, so it doesn't have the concurrency benefits of IOCP, but it allows you to implement a standard reactor pattern without having a limit to the number of handles (like WSAWaitForMultipleEvents).


I'm confused, isn't Reactor pattern where the thread blocks waiting on multiple event sources? That would be select(), which windows supports. The Proactor pattern is where there is a single callback per call, that you can do via ReadFileEx/WriteFileEx.


Not possible.

I've checked Boost.Asio sources that do have reactor style operations and use IOCP. For all reactor style operations separate thread with select is used instead of IOCP.


Have you tried passing zero nNumberOfBytesToRead to, for example ReadFile(socket_fd, ..)?

Maybe it will help to get the "read ready" event.

0

精彩评论

暂无评论...
验证码 换一张
取 消