Mohamad-Jaafar NEHME
Mohamad-Jaafar NEHME

Reputation: 1215

Are there any constraints on closing sockets in C++?

Could I close the sending (TCP) socket whenever I want?

Are there any cases to avoid using close(socket_name)?

Upvotes: 0

Views: 81

Answers (1)

user207421
user207421

Reputation: 311023

could I close the sending (TCP) socket whenever I want?

Yes, subject to below.

Are there any cases to avoid using close(socket_name)?

Yes. You shouldn't close when you are concurrently blocked in an operation on that socket, e.g. recv(), send(), select(), unless the surrounding code is written so as to handle EBADF correctly.

Upvotes: 1

Related Questions