Hi,
I'm currently using a thread to process a queue with asynchronous Connect and Send operations. Now I also want to make receive asynchronous. The problem with receiving however is that now it doesn't block the main program, but it blocks the asynchronous processing queue, so my socket still becomes useless until I receive something. What is the equivalent of "select" with SFML?
This is my current thread code:
void TCPThread( void* userdata )
{
TCPSocket* sock = (TCPSocket*)userdata;
while ( true )
{
if ( sock->queue.size() > 0 )
{
TCPOperation op = sock->queue[0];
switch ( op.op )
{
case 0:
sock->connected = false;
sock->connected = sock->sock.Connect( op.arg2, op.arg1, op.arg4 ) == sf::Socket::Done;
break;
case 1:
sock->sock.Send( op.arg1, op.arg3 );
break;
}
sock->queue.pop_front();
}
}
}
Also, what is the use of SetBlocking? There is no way to check if you're connected yet.