I'm currently writing a multi-threaded server where each thread has an io_context and a list of task objects to execute, with each task object having an associated ip::tcp::socket object.
For load-balancing I'm sometimes migrating tasks from one thread to another, however I'd like to migrate their sockets as well without dropping connection.
I could simply pass ownership of the socket object between threads, however the socket's io_context will remain that of its original thread, which would add significant complexity/slow-down.
Is there any way for me to keep a socket connection whilst moving it to a different io_context? Or is there another recommended approach?
Many thanks
io_context
really owns the socket. I suppose it owns the services, and it definitely owns the pending/active handlers. Now, I /think/ with sockets, it's just the handle that gets actually shared. At least, I've run with this (multipleio_service
s and passing sockets to and fro) for some time (years) and didn't observe any problems with that. Interesting question though. +1 – Ustkamenogorsk