[asio-users] Different io_service for TLS handshake and read/write
Brought to you by:
chris_kohlhoff
From: Michi H. <mic...@cr...> - 2018-11-30 01:36:21
|
I had a look at the answer in this thread: https://sourceforge.net/p/asio/mailman/message/3802402/ My situation is similar, but differs slightly. I have an io_service with a single thread that waits for incoming connections on an acceptor instance. Once the connection is established, I call async_handshake() to establish a TLS connection. This works fine, no problem. However, what I want to do is have the handshake performed by the acceptor thread, but use a different io_service with its own separate thread to perform all the I/O work once the handshake is complete. The motivation is CPU affinity, avoid context switches and locking, and avoid having lots of incoming TLS connections delay the I/O for already-established connections. I can’t work out how to do this. The socket embeds the io_service, the ssl stream embeds the socket, and the async_read()/async_write() methods are on the stream, so I can’t see how I can do the handshake in one thread, and transfer all subsequent I/O activity to a different thread once the handshake is complete. Any suggestions for how to achieve this? |