You have 2 choices here. Either you call isReady before any read() operation.
If isReady() returns true, then there is something to read.
But, there isn’t anything like that for write (isReady doesn’t check if the socket is ready to write more data), so beware.
Either, you’ll have to create a new class (let’s call it NonBlockingSocket).
Copy and paste the Socket class, and rename Socket by NonBlockingSocket
Then search of “ioctlsocket” in google for a method to put the socket in non blocking mode.
basically it’s like :
int mode = isBlocking ? 1 : 0;
ioctlsocket(handle, FIONBIO, &mode);
Socket class in Juce is very young, and a lot of the methods in there are blocking calls (like read, write, connect, waitForNextConnection).
Worse, the connect method is blocking, and the socket is, by default, put i n blocking mode, so the connect() method will block, whatever the timeout you pass in.
Juce, if you read this, please add a setBlockingMode() to the Socket class, and add a parameter to isReady() to permit select’ing on the write state too. That way, we will be able to “setBlockingMode(false)”, then “connect()”, and then wait with “isReady(true)” until the socket is writeable , meaning it’s connected.
Every read and write could be checked first with isReady(read ? false : true) to know if it’s going to block…