vs_integration/src/SocketConnection.cpp
//------------------------------------------------------------------------------
// This private function reads the command using our communications protocol.
//------------------------------------------------------------------------------
This private function reads the command using our communications protocol.
This private function reads the command using our communications protocol .
bool SocketConnection::ReadCommand(int socket,CString& command) {
unsigned char buf[4];
char* cmd;
int res;
int len;
	WSAAsyncSelect(socket, connection->m_ProxyHwnd, 0, 0);
	unsigned long disable_nonblocking = 0;
	ioctlsocket(socket, FIONBIO, &disable_nonblocking);
    res = recv(socket, (char*)buf, 4, 0);
	if(res!=4) return false;
    len = (unsigned)buf[0] | ((unsigned)buf[1] << 8) | ((unsigned)buf[2] << 16) | ((unsigned)buf[3] << 24);
	if(len>0) {
       cmd = new char [len+1];
	   int readed = 0;
       while((len-readed) > 0){
	       int res = recv(socket, cmd+readed, len-readed, 0);
		   if(res < 0) {
              WSAAsyncSelect(socket, connection->m_ProxyHwnd, CLIENT_SOCKET_MESSAGE, FD_READ | FD_CLOSE);
	          return false;
		   } else {
	          readed+= res;
		   }
	   }
	   cmd[readed]=0;
	   command = cmd;
	   delete cmd;
	} else {
	   command = "";
	}
    WSAAsyncSelect(socket, connection->m_ProxyHwnd, CLIENT_SOCKET_MESSAGE, FD_READ | FD_CLOSE);
    return true;
}
bool SocketConnection :: ReadCommand ( int socket , CString & command ) { unsigned char buf [ 4 ] ; char * cmd ; int res ; int len ; WSAAsyncSelect ( socket , connection -> m_ProxyHwnd , 0 , 0 ) ; unsigned long disable_nonblocking = 0 ; ioctlsocket ( socket , FIONBIO , & disable_nonblocking ) ; res = recv ( socket , ( char * ) buf , 4 , 0 ) ; if ( res != 4 ) return false ; len = ( unsigned ) buf [ 0 ] | ( ( unsigned ) buf [ 1 ] << 8 ) | ( ( unsigned ) buf [ 2 ] << 16 ) | ( ( unsigned ) buf [ 3 ] << 24 ) ; if ( len > 0 ) { cmd = new char [ len + 1 ] ; int readed = 0 ; while ( ( len - readed ) > 0 ) { int res = recv ( socket , cmd + readed , len - readed , 0 ) ; if ( res < 0 ) { WSAAsyncSelect ( socket , connection -> m_ProxyHwnd , CLIENT_SOCKET_MESSAGE , FD_READ | FD_CLOSE ) ; return false ; } else { readed += res ; } } cmd [ readed ] = 0 ; command = cmd ; delete cmd ; } else { command = " " ; } WSAAsyncSelect ( socket , connection -> m_ProxyHwnd , CLIENT_SOCKET_MESSAGE , FD_READ | FD_CLOSE ) ; return true ; }
This private function reads the command using our communications protocol.
This private function reads the command using our communications protocol .