You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Part of the contract would be that anything that calls the OS would have to have the std::io::ErrorKind::WouldBlock in its spec (this is assuming linux)
I would be happy to add this functionality, as it would be great to have in our production code-base.
The text was updated successfully, but these errors were encountered:
That's what we have been using, but we have realised that async in our code-base was a mistake, and we are migrating away from it.
What we ended up doing, for now, is this:
pubstructBootstrapTcpListener{poll:Poll,events:Events,server:TcpListener,// HACK : create variable to move ownership of mio_server to the thread// if mio_server is not moved, poll does not receive any event from listener_mio_server:MioTcpListener,}pubenumPollEvent{NewConnection((TcpStream,SocketAddr)),Stop,}implBSEventPollerforBootstrapTcpListener{fnpoll(&mutself) -> Result<PollEvent,BootstrapError>{self.poll.poll(&mutself.events,None).unwrap();// Confirm that we are not being signalled to shut downifself.events.iter().any(|ev| ev.token() == STOP_LISTENER){returnOk(PollEvent::Stop);}// Ther could be more than one connection ready, but we want to re-check for the stop// signal after processing each connection.returnOk(PollEvent::NewConnection(self.server.accept().map_err(BootstrapError::from)?,));}}implBootstrapListenerStopHandle{/// Stop the bootstrap listener.pubfnstop(self) -> Result<(),BootstrapError>{self.0.wake().map_err(BootstrapError::from)}}
...and in the main event loop of the server, instead of using std::net::TcpListener::accept(...)?, we use our poll and match on the return enum.
Previously we would have a dedicated listener thread, and two crossbeam channels, one for a connection, one for a stop-signal broadcast:
loop{let conn = select!{
recv(stopper_rx) -> _ => returnOk(()),
recv(conn_rx) -> conn => conn,
};// ...validate connection before dispatching to a system-thread to handle}
What the change meant is that we no longer have a need for a dedicated listener thread, or a buffer of connections.
I see that my "MVP" is probably a bad label, and probably a distraction.
instead of:
This one, you must spin up a dedicated loop that can block on a listen, but how about:
Because of the selectors limitation to be only able to work on channels, we had to instead write a helper method like so. Here is an MVP:
Part of the contract would be that anything that calls the OS would have to have the
std::io::ErrorKind::WouldBlock
in its spec (this is assuming linux)I would be happy to add this functionality, as it would be great to have in our production code-base.
The text was updated successfully, but these errors were encountered: