/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ int CWsHook::WSARecv(SOCKET s, LPWSABUF lpBuffers, DWORD dwBufferCount, LPDWORD lpNumberOfBytesRecvd, LPDWORD lpFlags, LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine) { int ret = SOCKET_ERROR; if (tlsIndex != TLS_OUT_OF_INDEXES) TlsSetValue(tlsIndex, 0); if( _WSARecv ) ret = _WSARecv(s, lpBuffers, dwBufferCount, lpNumberOfBytesRecvd, lpFlags, lpOverlapped, lpCompletionRoutine); void * sid = NULL; if (dlg) sid = dlg->GetSchannelId(s); if( !sid && dlg && ret != SOCKET_ERROR && lpBuffers && dwBufferCount && lpNumberOfBytesRecvd && *lpNumberOfBytesRecvd && !lpOverlapped && !lpCompletionRoutine ) { DWORD bytes = *lpNumberOfBytesRecvd; DWORD i = 0; while( i < dwBufferCount && bytes > 0 ) { DWORD chunk = min(lpBuffers[i].len, bytes); if( chunk ) { bytes -= chunk; if( lpBuffers[i].buf ) dlg->SocketRecv(s, chunk, (LPBYTE)lpBuffers[i].buf ); } i++; } } return ret; }
static bool b_recfrom( const int t ) { bool result; if( !has_mac_read_space(t) ) { D(bug("<%d> read stalled, mac cannot accept any more data\r\n", t)); sockets[t].stream_to_mac_stalled_until = GetTickCount() + sockets[t].resend_timeout; return true; } int ret = _WSARecv( sockets[t].s, sockets[t].buffers_read, sockets[t].buffer_count_read, &sockets[t].bytes_received, &sockets[t].flags_read, &sockets[t].overlapped_read, tcp_read_completion ); if(ret == SOCKET_ERROR) { int socket_error = _WSAGetLastError(); if(socket_error == WSA_IO_PENDING) { D(bug("<%d> WSARecv() i/o pending\r\n", t)); result = true; } else { D(bug("<%d> WSARecv() returned error %d\r\n", t, socket_error)); result = false; } } else /*if(ret == 0) */ { D(bug("<%d> WSARecv() ok\r\n", t)); // Completion routine call is already scheduled. result = true; } return result; }