Inside the Tick function I check the data on the sending and receiving:
if (Socket == NULL || Socket->GetConnectionState() != ESocketConnectionState::SCS_Connected))
{
// do something
}
SendBuf();
Recv();
But even if the connection is in fact already closed by the server, the Socket->GetConnectionState()! = ESocketConnectionState::SCS_Connected always true.
In standard BSD sockets, if the recv() call returns 0, this indicates the connection was closed gracefully. Currently our wrapper function, FSocketBSD::Recv(), only returns a bool, and doesn’t provide this information, either directly or through GetConnectionState(). We’re now tracking a task to expose this information.
In the meantime, you can work around this in a couple ways:
Modify the Recv() function to
return an int instead of a bool, return the result of the BSD recv() directly, and check that, or
If you know for sure your socket is an FSocketBSD, you can use GetNativeSocket(), call recv() directly, and check the return value. Note that this will not set the internal LastActivityTime used in GetConnectionState().
It seems that this issue makes it quite difficult if not impossible to use the socket subsystem in a production-ready way (robust and portable) without switching to a source build. At the same time, it seems that fixing it would be really trivial for an Epic staff member?
This issue has been open for over a year now. Any chance in bumping its priority a bit?
Also, I should mention that I don’t see a way to make Recv non-blocking, so in order to use its return value, I’d need to be okay with blocking. I think there should be a non-blocking method of checking whether the connection is closed.