I am facing issue with sockets select api, code works fine when compiled on unix (solaris) and windows(VC++), but when use mingw it hangs on select call().
 
1st time it goes fine but 2nd time when readSocket is invoked its getting hung on select call.
 
appriciate your inputs. (please see code snippet below, anything specifc need to done? )
 
g++ - 3.4.5, (added -lws2_32 and preprocessor flag: __USE_W32_SOCKETS)
 
Thanks,
-abhijit
 

readSocket(SOCKET socket, BYTEPTR lpBuffer, UINT dwSize, UINT dwTimeout) {

if (lpBuffer == NULL || dwSize < 1L)

return 0;

fd_set fdRead = { 0 };

TIMEVAL stTime;

TIMEVAL *pstTime =

NULL;

if ( INFINITE != dwTimeout ) {

stTime.tv_sec = dwTimeout/1000;

stTime.tv_usec = dwTimeout % 1000;

pstTime = &stTime;

}

SOCKET s = (SOCKET) socket;

// Set Descriptor

if ( !FD_ISSET( s, &fdRead ) )

FD_SET( s, &fdRead );

// Select function set read timeout

int dwBytesRead = 0;

int res = select( s+1, &fdRead, NULL, NULL, pstTime );

if ( res > 0)

{

dwBytesRead = recv( s, (CHARPTR)lpBuffer, dwSize, 0);

}

return dwBytesRead;
 
}