@@ -210,6 +210,17 @@ class Logger
210210
211211std::string LongThreadName (const char * exe_name);
212212
213+ using Stream = kj::Own<kj::AsyncIoStream>;
214+
215+ inline SocketId StreamSocketId (const Stream& stream)
216+ {
217+ if (stream) KJ_IF_MAYBE (fd, stream->getFd ()) return *fd;
218+ #ifdef WIN32
219+ if (stream) KJ_IF_MAYBE (handle, stream->getWin32Handle ()) return reinterpret_cast <SocketId>(*handle);
220+ #endif
221+ throw std::logic_error (" Stream socket unset" );
222+ }
223+
213224// ! Event loop implementation.
214225// !
215226// ! Cap'n Proto threading model is very simple: all I/O operations are
@@ -308,11 +319,12 @@ class EventLoop
308319 // ! Callback functions to run on async thread.
309320 std::optional<CleanupList> m_async_fns MP_GUARDED_BY (m_mutex);
310321
311- // ! Pipe read handle used to wake up the event loop thread.
312- int m_wait_fd = -1 ;
322+ // ! Socket pair used to post and wait for wakeups to the event loop thread.
323+ kj::Own<kj::AsyncIoStream> m_wait_stream;
324+ kj::Own<kj::AsyncIoStream> m_post_stream;
313325
314- // ! Pipe write handle used to wake up the event loop thread .
315- int m_post_fd = - 1 ;
326+ // ! Synchronous writer used to write to m_post_stream .
327+ kj::Own<kj::OutputStream> m_post_writer ;
316328
317329 // ! Number of clients holding references to ProxyServerBase objects that
318330 // ! reference this event loop.
@@ -797,13 +809,11 @@ kj::Promise<T> ProxyServer<Thread>::post(Fn&& fn)
797809// ! over the stream. Also create a new Connection object embedded in the
798810// ! client that is freed when the client is closed.
799811template <typename InitInterface>
800- std::unique_ptr<ProxyClient<InitInterface>> ConnectStream (EventLoop& loop, int fd )
812+ std::unique_ptr<ProxyClient<InitInterface>> ConnectStream (EventLoop& loop, kj::Own<kj::AsyncIoStream> stream )
801813{
802814 typename InitInterface::Client init_client (nullptr );
803815 std::unique_ptr<Connection> connection;
804816 loop.sync ([&] {
805- auto stream =
806- loop.m_io_context .lowLevelProvider ->wrapSocketFd (fd, kj::LowLevelAsyncIoProvider::TAKE_OWNERSHIP );
807817 connection = std::make_unique<Connection>(loop, kj::mv (stream));
808818 init_client = connection->m_rpc_system ->bootstrap (ServerVatId ().vat_id ).castAs <InitInterface>();
809819 Connection* connection_ptr = connection.get ();
@@ -854,10 +864,9 @@ void _Listen(EventLoop& loop, kj::Own<kj::ConnectionReceiver>&& listener, InitIm
854864// ! Given stream file descriptor and an init object, handle requests on the
855865// ! stream by calling methods on the Init object.
856866template <typename InitInterface, typename InitImpl>
857- void ServeStream (EventLoop& loop, int fd , InitImpl& init)
867+ void ServeStream (EventLoop& loop, kj::Own<kj::AsyncIoStream> stream , InitImpl& init)
858868{
859- _Serve<InitInterface>(
860- loop, loop.m_io_context .lowLevelProvider ->wrapSocketFd (fd, kj::LowLevelAsyncIoProvider::TAKE_OWNERSHIP ), init);
869+ _Serve<InitInterface>(loop, kj::mv (stream), init);
861870}
862871
863872// ! Given listening socket file descriptor and an init object, handle incoming
0 commit comments