i found something
that would be
int WaitForServerConnectionUnblocked()
{
u_long no_block=1;
ioctlsocket(clientSock,FIONBIO,&no_block);
//connect to the server
// iResult = connect(client, (sockaddr*)&server, sizeof(server));
int retVal = connect(clientSock,(LPSOCKADDR)&serverInfo, sizeof(serverInfo));
if( retVal == SOCKET_ERROR)
{
int iError = WSAGetLastError();
//check if error was WSAEWOULDBLOCK, where we'll wait
if(iError == WSAEWOULDBLOCK)
{
/// cout << "Attempting to connect.\n";
fd_set Write, Err;
TIMEVAL Timeout;
FD_ZERO(&Write);
FD_ZERO(&Err);
FD_SET(clientSock, &Write);
FD_SET(clientSock, &Err);
Timeout.tv_sec = 0;
Timeout.tv_usec = 30*1000;
int iResult = select(0, NULL, &Write, &Err, &Timeout);
if(iResult == 0)
{
// cout << "Connect Timeout (" << TimeoutSec << " Sec).\n";
return 0;
}
else
{
if(FD_ISSET(clientSock, &Write))
{
// cout << "Connected!\n";
return 1;
}
if(FD_ISSET(clientSock, &Err))
{
// cout << "Select error.\n";
return 0;
}
}
}
else
{
// cout << "Failed to connect to server.\n";
// cout << "Error: " << WSAGetLastError() << endl;
// WSACleanup();
return 0;
}
}
else
{
//connected without waiting (will never execute)
//cout << "Connected!\n";
return 1;
}
}
/////////////////
i would yet need a bit to digest it
it looks like blocking but here you
could just set the timeout to small
value so the client will not half-hang as with blocked where it was also like nonblocking but with a timeout like 1.5 seconds, here i set 30 ms and it seem to work
(i assume here that when i returned 1 it is connected , when returned 0 it is not connected and i should repeat the attempts by calling it again)
sometiomes thoug rarely it seems not to connect when i set up both client and server and it probably would need to be inspected yet,
maybe there is yet some bug somewhere