Replies: 4 comments 5 replies
-
|
Is there a way to make the changes without changes to user interface? I don't like to introduce this
I have been thinking about this Meanwhile, calls to With the Though we provide |
Beta Was this translation helpful? Give feedback.
-
|
As a side note, That makes me wondering if we shouldn't just use
The only drawback I see is that it is written in C. There are C++ wrappers, but I couldn't asses the quality, overhead and documentation of these. @gxuu @magniloquency @sharpener6 Thoughts? |
Beta Was this translation helpful? Give feedback.
-
|
Another problem to achieve a common abstraction for all the sockets is that on Windows server and client FD (the ones fed into |
Beta Was this translation helpful? Give feedback.
-
|
I think this is going in the right direction. I agree that the code path for receiving an event on Windows is strange, it feels a bit like putting a round peg in a round hole. I'm not sure that I totally understand the purpose / shape of this I'm not too familiar with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I spent the past few days trying to find a common abstraction API for system calls (sockets, pipes, files ...) that works with Windows and Unixes non-blocking sockets (Epoll, kQueue, Windows's IOCP ...).
Reactive vs proactive events
The main issue, as pointed by @gxuu, is that Epoll, kQueue and
select()are reactive, while IOCP is proactive:That makes it hard to provide a common
SocketandEventPoolAPI, as the calling code would have to reverse the calling order of the respective calls:Current implementation
@gxuu solved this problem by requiring the user code to always call
socket.prepare_read()before waiting on the event loop, with the call being a no-op on UNIXes.While that works, it complicates the socket logic as, contrary to the simplified example, the call to
prepare_read()might happen in a different iteration of the event loop (as we are handling multiple sockets).The second issue is that the current event loop cannot notify which actual syscall completed (i.e. you don't know which
prepare_read()event is associated with the event loop returned event). This creates weird code paths.Compare this with Python event loop API (Boost's asio behaves similarly):
Proposed changes
I'm proposing:
Transportclass, provided by theEventLoopimplementation and wrapping lower level sockets, pipe, file APIs. This class "wraps" basic I/O calls (read(),write()...) inside the event loop. Python asyncio uses a similar class internally;void read(size_t n, std::function<void(ReadResult)>). That removes the need of a call toprepare_read(), and create a 1:1 matching for I/O calls and their respective results. Callbacks are functionally equivalent to asyncio/asio.For example, usage would be:
Beta Was this translation helpful? Give feedback.
All reactions