fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
769 stars 126 forks source link

socket.is_connected not working #65

Open ryanwe1ss opened 2 years ago

ryanwe1ss commented 2 years ago

Hi, I've been trying to check if my socket that I have connected to a server is active in which it obviously is because I am able to send data back and forth, but is there any way I can check because I've been trying to use "socket.is_connected()" but it seems to be returning the same value no matter if it is connected or not. Currently using TCP sockets.

fpagliughi commented 2 years ago

Yeah, I had meant that to just be a check after the initial connection was attempted, succeeded, and is not yet closed. It's literally just checking for a valid socket descriptor (file handle).

Maybe it could be made more useful. I'd need to think about it a bit. Usually you detect a closed connection by a failed read or write.

AndersHogqvist commented 1 week ago

Yeah, I had meant that to just be a check after the initial connection was attempted, succeeded, and is not yet closed. It's literally just checking for a valid socket descriptor (file handle).

Maybe it could be made more useful. I'd need to think about it a bit. Usually you detect a closed connection by a failed read or write.

I was just about to ask the same question as @ryanwe1ss but that explains it. I would suggest changing the name of that method to something like is_valid() or similar instead of is_connected() if that isn't what it's actually checks.

fpagliughi commented 1 week ago

Yeah, I agree the name is misleading; a poor choice. I will consider renaming it with the v2 release. Then I can make some breaking changes.