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.
精彩评论