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?