HI all, sorry to bug u guys again, but I needed your help.
So far, I got the snippet of the board here, and try to modified it so that it can handle multi connections. but I seem to have problem modifying it.. coz I am still confusing about winsock stuff.

here what I got:

EventMode proc Param:DWORD

LOCAL Count:DWORD
LOCAL CurrentEvent:DWORD

jmp @F
Connection1C db "test",0
Connection1T db "debuging",0
@@:
invoke MessageBox, NULL, addr Connection1T, addr Connection1C, MB_OK

mov Count, 0
@CreateNewEvent:
invoke WSACreateEvent ;create a event for listening
mov dword ptr, eax ;save handle to array
inc Count ;use with WSAWaitForMultipleEvents
.IF (Count==1)
mov hEventListen, eax
invoke WSAEventSelect, hListenSocket, eax, FD_ACCEPT+FD_CLOSE
.ELSE
invoke WSAEventSelect, hListenSocket, eax, FD_READ+FD_WRITE+FD_CLOSE
.ENDIF

@NextEvent:
invoke WSAWaitForMultipleEvents, Count, addr pListenEvent, FALSE, INFINITE, FALSE ;<--this call seems to always return 0xFFFFFFFF

;eax is now the index of the event object that got signaled
mov CurrentEvent, eax
.IF (eax==hEventListen)
invoke WSAEnumNetworkEvents, hListenSocket, hEventListen, addr WSAEventListen
.ELSE
invoke WSAEnumNetworkEvents, hListenSocket, CurrentEvent, addr WSAEventListen
.ENDIF
cmp WSAEventListen.lNetworkEvents, FD_ACCEPT
jne @READ
lea edi, pListenEvent
add edi, 4
mov pListenEvent, edi
jmp @F
ConnectionC db "Accepted:",0
ConnectionT db "Incoming Connection",0
@@:
invoke MessageBox, NULL, addr ConnectionT, addr ConnectionC, MB_OK
jmp @CreateNewEvent
@READ:
cmp WSAEventListen.lNetworkEvents, FD_READ
jne @SEND
;do recv stuff
@SEND:
cmp WSAEventListen.lNetworkEvents, FD_WRITE
jne @CLOSE
;do send stuff
@CLOSE:
cmp WSAEventListen.lNetworkEvents, FD_CLOSE
jne @MORE
invoke WSACloseEvent, CurrentEvent
@MORE:
jmp @NextEvent

ret
EventMode endp

what I am trying to do here is:
1)create main event so it can handle FD_ACCEPT, FD_CLOSE
2)when the FD_ACCEPT notified, I go back and create a new event for that connection, and let it handle FD_READ, FD_WRITE, and FD_CLOSE
3) this will keep repeating until EventMode thread terminated

after I noticed that it can accept multi connections but it seem to fall into the FD_ACCEPT notification in a forever loop. what I mean is when I create a connection to this server, the accept msg box keep poping up, I can't cancel it.


would somebody help me fix this please?


sincerely,
Posted on 2002-03-12 12:28:32 by Yanda
I have not looked at it long, but one thing I see wrong is that you are not creating a new thread for each accept. After the main thread is signaled with an accept, use CreateThread() to spawn a new thread. Also look at WSAResetEvent(), otherwise your program will just spin.
Posted on 2002-03-12 15:26:41 by bdjames
If you get it working... Please post the source, this is something I was/is struggling with for some time

Sliver
Posted on 2002-03-13 00:44:15 by Sliver
Ok sure!

I feel so happy that I can also help someone too :alright:


keep an eye on :grin:
Posted on 2002-03-13 02:21:10 by Yanda
I would be interested too.:)
Posted on 2002-03-13 07:16:17 by TCT
The problem is that the lNetworkEvents member is a bitmask where one or more bits are set (corresponding to a FD_* value), indicating which of the network events occurred. You are comparing against each value, but more than one event can occur.
Here's a piece of code from my blueice webserver:


; Translates a network event into one or more connthread messages
; returns 1 on success, 0 on error (dwLastError is set)
CST_TranslateNetEvents proc uses ebx edi esi lpTHIS:DWORD
LOCAL networkEvents:WSANETWORKEVENTS
SetObject edi, CServerThread

; Look which network events occurred:
invoke WSAEnumNetworkEvents, [edi].hClientSocket, [edi].hNetworkEvent,
addr networkEvents

; If eax is not null, an error occurred:
.IF eax
mov [edi].dwLastError, ST_ERR_INTERNALFUNCTIONFAILED
xor eax, eax
ret
.ENDIF

; initialize:
mov ebx, dword ptr [networkEvents]
xor esi, esi


; Bit test on server network events. Push each translated msg on stack,
; esi is the msg counter:
test ebx, FD_READ
jz @F
push STMSG_FD_READ
inc esi
@@:
test ebx, FD_WRITE
jz @F
push STMSG_FD_WRITE
inc esi
@@:
test ebx, FD_CLOSE
jz @F
push STMSG_FD_CLOSE
inc esi
@@:

; Pop (esi) messages from stack and send them
.WHILE esi
pop eax
method edi, CServerThread, SendMsg, eax
.IF eax!=1
mov [edi].dwLastError, eax
xor eax, eax
ret
.ENDIF
dec esi
.ENDW

xor eax, eax
inc eax

ReleaseObject edi
ret
CST_TranslateNetEvents endp


Thomas

edit, sidenote:The code above tests if an event has happend, and if it has it pushes a message onto the stack. The loop after it pops all values off again and sends them one by one. You can simply test for the events in your code, this is just how my code's internals work.

edit2:. Just found a bug in my message send loop above :), if something goes wrong the stack gets corrupted...
Posted on 2002-03-13 09:18:49 by Thomas