To close a Tcp client, which one should be used, io_context.stop()
or socket.close()
? What aspects should be considered when making such a choice?
As far as I know, io_context
is thread-safe whereas socket
is not.
So, I can invoke io_context.stop()
in any thread which may be different from the one that has called io_context.run()
. But for socket.close()
, I need to call io_context.post([=](){socket.stop()})
if socket
object is called in a different thread(e.g. the said thread calls aiso::async_read(socket, ...)
).
Aucun commentaire:
Enregistrer un commentaire