Activated Azio Sockets Have Proper RAII Cleansing

I tried to view the source, but I can not move this part of the template code. Basically: this is what the documentation says (for close() ):

 Remarks For portable behaviour with respect to graceful closure of a connected socket, call shutdown() before closing the socket. 

I can do it manually, but if possible, it would be nice to rely on RAII.

So, if I have a socket that goes out of scope, do I need to call shutdown() and close() on it, or will it be done automatically?

+6
source share
1 answer

You can rely on a socket that performs the correct cleanup using RAII.

When an IO object, such as a socket, is destroyed, its destructor calls destroy() on the IO object service, passing the implementation_type instance on which the IO object service will run. SocketService states that destroy() will implicitly cancel asynchronous operations as-if, by calling close() on a service that has post is_open() returns false. Additionally, the close() will complete outstanding asynchronous operations as soon as possible. Handlers for canceled operations will be passed the error code boost::asio::error::operation_aborted and scheduled for a deferred call to io_service . These handlers are removed from io_service if they are either called from the thread processing the event loop or io_service destroyed .

+4
source

All Articles