Hello everybody, I've wrote a thread which relays data from one socket to another, but I now found a problem which I can't understand. Maybe someone can say what it is... Here are some sources:

SOCK_BUF Equ (32*1024)

; Some used functions
FdSet Proc USES Eax Ebx Edx Sock:DWORD, lpFd:DWORD

mov ebx, lpFd

mov eax, (fd_set Ptr [ebx]).fd_count
mov edx, Sock
push ebx
lea ebx, (fd_set Ptr [ebx]).fd_array
mov Dword Ptr [ebx + eax * SIZEOF DWORD], edx
inc eax
pop ebx
mov (fd_set Ptr [ebx]).fd_count, eax
FdSet Endp

FdZero Proc USES Ebx lpFd:DWORD

mov ebx, lpFd
mov (fd_set Ptr [ebx]).fd_count, 0
FdZero Endp

FdIsSet Proc USES Ebx Ecx Sock:DWORD, lpFd:DWORD

mov Result, FALSE

mov ebx, lpFd
mov ecx, (fd_set Ptr [ebx]).fd_count
lea ebx, (fd_set Ptr [ebx]).fd_array

.if ecx
dec ecx
mov eax, Dword Ptr [ebx + ecx * SIZEOF DWORD]

.if eax == Sock
mov Result, TRUE
.until Ecx == 0 || Result == TRUE

mov eax, Result
FdIsSet Endp

FdInit Proc Sock:DWORD, lpFd:DWORD

invoke FdZero, lpFd
invoke FdSet, Sock, lpFd
FdInit Endp

;[B]The code in which the problem is...[/B]
ClientSock Proc sserver:DWORD, sclient:DWORD
LOCAL rdFds :fd_set


@GetMemory SOCK_BUF
mov lpBuf, eax

invoke InitializeCriticalSection, ADDR lpCrit
[B]invoke Sleep, 50[/B] ; Here is the problem! I'll say about it at the bottom
invoke FdZero, ADDR rdFds
invoke FdSet, sserver, ADDR rdFds
invoke FdSet, sclient, ADDR rdFds
invoke select, NULL, ADDR rdFds, NULL, NULL, NULL
.if eax == SOCKET_ERROR || eax == 0
jmp _exit
invoke EnterCriticalSection, ADDR lpCrit

invoke FdIsSet, sserver, ADDR rdFds
.if eax
invoke recv, sserver, lpBuf, SOCK_BUF, 0
.if eax == SOCKET_ERROR || eax == 0
jmp _exit
invoke send, sclient, lpBuf, eax, 0

invoke FdIsSet, sclient, ADDR rdFds
.if eax
invoke recv, sclient, lpBuf, SOCK_BUF, 0
.if eax == SOCKET_ERROR || eax == 0
jmp _exit
invoke send, sserver, lpBuf, eax, 0

invoke LeaveCriticalSection, ADDR lpCrit
jmp _new

invoke DeleteCriticalSection, ADDR lpCrit

@FreeMemory lpBuf

invoke closesocket, sserver
invoke closesocket, sclient

invoke ExitThread, 0
ClientSock Endp

The problem is that if there is no that string (Sleep, 50) select doesnt return. But the data is there! Can someone explain this?:confused:
Posted on 2004-03-09 19:19:10 by The CHEMI$T