When does FSocket block?

Considering ClientSocket is an FSocket, is this ideal for getting data from the socket as quick as possible?

while (this->IsAlive)
{
    if (this->ClientSocket->HasPendingData(dataSize) || this->ClientSocket->Wait(ESocketWaitConditions::WaitForRead, FTimespan::FromSeconds(1)))
    {
    }
}

I would honestly prefer this->ClientSocket->HasPendingData(dataSize) to be blocking but as far as I can tell, it is not.

HasPendingData() is specifically meant as a polling mechanism to check whether there is data without blocking. If you want to block, just use Wait() by itself. It is like HasPendingData(), but blocks. Use one or the other, but not both.

What happens when, if it takes a long time before returning to Wait() and between that time, the socket has received more data? Does it wait for the next read or does it know there’s data and continue?

The FTimespan parameter in Wait() is the maximum time to wait. If you call it with WaitForRead, it will unblock as soon as data is available for reading. It will also unblock if the specified timeout is exceeded.

So in your example code, the Wait() will block until there is either data ready for reading, or if one second has passed, whichever comes first.

Thanks for answering. I wasn’t sure if the socket had pending data and Wait() was called if it would wait until the socket received more data, or if it wouldn’t wait and continue.

I would like to look at the socket source for windows. Would you by chance know the subclass/es name/s?

Windows uses BSD sockets now, which are implemented in FSocketBSD (/Runtime/Sockets/Private/BSDSockets/SocketsBSD.h).

Thanks! (This is here because I needed more character to say thanks.)