views:

232

answers:

4

Hello,

Is there any scalable Win32 API (like IOCP not like select) that gives you reactor style operations on sockets? 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?

A: 

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.

Frank Schwieterman
Yes, select like operations are what I need but select is not as scalable as epoll/kqueue.
Artyom
I think WaitForMultipleObjectsEx will do the same thing for you as select, though not sure if it will address your perf concerns.
Frank Schwieterman
A: 

Are you asking how to use completion ports on Windows? If so, you will probably want to start with CreateIoCompletionPort.

Or do you want to know how to do an asynchronous select operation? In that case you want to look at the WSAAsyncSelect API.

Gabe
No, added "Even more clearification" section
Artyom
It really looks like WSAAsyncSelect is what you want. Can you please explain how it isn't?
Gabe
A: 

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.

Artyom
A: 

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

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

Dmitry Sychov