Hello, my server runs single io_service and asynchronosly accepts incoming connections (creating new sockets for each incoming connection).
Usage of connection happens in such ways:
- calls to socket::async_write() from multiple threads (embraced to mutex) at any time
- handling socket::acync_read() (which runs within io_service' thread as I understand the documentation)
- single call to socket::shutdown() at any moment from some other thread
Previusly I used multiple of mutexes to cleanly wait for all current asynchronous read/write handlers: write function incremented "writes" variable which then was used on socket shutdown to wait the same amount of write handlers - but deadlock sometimes happend at moment of waiting write handlers. So I referred to socket::shutdown()'s documentation which say "Any asynchronous send, receive
or connect operations will be cancelled immediately" - and don't wait any asynchronous operations for now and everything seems to work fine for now (what scares me).
Is it safe to do so? How must I safely handle all currenlty running asynchronous read/write handlers?
In case of boost.asio waits for all asynchronous operations to stop inside socket::shutdown/close so, then, if to call it within one of such operations - deadlock will (theoretically must) happen - so, socket::close/shutdown isn't safe?
Thank you.