Something like...
Code:// Client send function int Send(void *pvBuffer, int iStillToSend) { int iRC = 0; int iSendStatus = 0; timeval SendTimeout; char *pBuffer = static_cast<char *>(pvBuffer); fd_set fds; FD_ZERO(&fds); FD_SET(Socket, &fds); // Set timeout SendTimeout.tv_sec = 0; SendTimeout.tv_usec = 250000; // 250 ms // As long as we need to send bytes... while(iStillToSend > 0) { iRC = select(0, NULL, &fds, NULL, &SendTimeout); // Timeout if(!iRC) return -1; // Error if(iRC < 0) return WSAGetLastError(); // Send some bytes iSendStatus = send(Socket, pBuffer, iStillToSend, 0); // Socket is of type // 'SOCKET' and is // the current // connection socket // Error if(iSendStatus < 0) return WSAGetLastError(); else { // Update buffer and counter iStillToSend -= iSendStatus; pBuffer += iSendStatus; } } return 0; }




Reply With Quote