Tonia Sanzo
Tonia Sanzo

Reputation: 355

Do you have to manually close boost::asio sockets if they are members of a shared_ptr object?

I have a socket that's a member of a shared_ptr object. Do I have to explicitly call socket.close() or is it safe to assume that it is closed automatically?

The reason I ask is because in this TCP Daytime Server Example the author doesn't explicitly call socket.close().

Upvotes: 1

Views: 73

Answers (1)

sehe
sehe

Reputation: 393114

It depends on when you need the socket to be closed.

In general, the socket desctructor causes the socket to close (because not doing so would amount to a resource leak).

Upvotes: 1

Related Questions