Is there a recommended way to abort a StreamingSocket::waitForNextConnection call? It blocks indefinitely until a connection is made. Is there no way to poll for a connection so I can kill my listener thread gracefully?
You’ll need to put the socket in non blocking mode.
Then call accept as usual, it’ll exit immediately with an error.
Then select when the socket is writable, it means it’s connected.
Select with a timeout, obviously.
Hi. I’m just now getting back to this issue. X-Ryl thanks for the response, but it makes no sense. Can you please elaborate? Can anyone else weigh in on this. It seems like waitForNextConnection is virtually useless if the wait can’t be gracefully aborted.
before doing a “waitForInputConnection()”, do a
if (socket.waitUntilReady(true, 200)) client = socket.waitForInputConnection()
I’m using this solution, it works perfectly.
Put the socket in non-blocking mode.
(see setSocketBlockingState function).
Then perform your own accept call, it will fail unless a connection is accepted.
Use this if you have multiple socket to monitor at once.
Ah. That’s much clearer. I think I’ll choose door #1. Thanks.