hi,
below I have attached my server procedure, its called when the worker thread created on startup.
I duno whats wrong with it, it seem that the event messages doesn't get process.
it only seem to process the first event, which is the accept event,, it ignore the rest :(
and when I tried to connect to the server with a dumy client, the result value for the connect function seem always FFFFFFFFh, I duno y.
can someone please help me check my proc below see what I did wrong???
thankx alots in adv,
Posted on 2002-12-25 02:38:11 by Yanda
below I have attached my server procedure, its called when the worker thread created on startup.
I duno whats wrong with it, it seem that the event messages doesn't get process.
it only seem to process the first event, which is the accept event,, it ignore the rest :(
and when I tried to connect to the server with a dumy client, the result value for the connect function seem always FFFFFFFFh, I duno y.
can someone please help me check my proc below see what I did wrong???
thankx alots in adv,
ListenProc proc
LOCAL hListenEvent:DWORD
LOCAL hClientEvent:DWORD
LOCAL pListenEvent:DWORD,pClientEvent:DWORD
LOCAL Count:DWORD
invoke WSAStartup, 101h, addr WSAdata
.IF (eax!=0)
;error initializing winsock lib
xor eax, eax
ret
.ENDIF
invoke socket, AF_INET, SOCK_STREAM, IPPROTO_IP
.IF (eax==INVALID_SOCKET)
;socket creation error
xor eax, eax
ret
.ENDIF
mov hListenSocket, eax
mov SA_IN.sin_family, AF_INET
invoke htons, szPort
mov SA_IN.sin_port, ax
mov SA_IN.sin_addr, INADDR_ANY
invoke bind, hListenSocket, addr SA_IN, sizeof SA_IN
.IF (eax!=0)
;binding error, check for error msg
xor eax, eax
ret
.ENDIF
invoke WSACreateEvent
mov hListenEvent, eax
mov [pListenEvent], eax
invoke WSAEventSelect, hListenSocket, hListenEvent, FD_ACCEPT+FD_CLOSE
invoke listen, hListenSocket, 5
.IF (eax==INVALID_SOCKET)
;listen error, check for error msg
xor eax, eax
ret
.ENDIF
@DoListen:
invoke WSAWaitForMultipleEvents, 1, addr pListenEvent, FALSE, INFINITE, FALSE
invoke WSAEnumNetworkEvents, hListenSocket, hListenEvent, addr WSAEventListen
test WSAEventListen.lNetworkEvents, FD_ACCEPT
jz @CheckServerClose
;accept the client
invoke accept, hListenSocket, addr SA_IN, SIZEOF SA_IN
mov hClientSocket, eax
invoke WSACreateEvent
mov hClientEvent, eax
mov [pClientEvent], eax
invoke WSAEventSelect, hClientSocket, hClientEvent, FD_READ+FD_WRITE+FD_CLOSE
@CheckClient:
invoke WSAWaitForMultipleEvents, 1, addr pClientEvent, FALSE, INFINITE, FALSE
invoke WSAEnumNetworkEvents, hClientSocket, hClientEvent, addr WSAEventClient
test WSAEventClient.lNetworkEvents, FD_READ
jz @CheckWrite
;do read
@CheckWrite:
test WSAEventClient.lNetworkEvents, FD_WRITE
jz @CheckClose
@CheckClose:
;do write
test WSAEventClient.lNetworkEvents, FD_CLOSE
jz @CheckClient
;do close
invoke closesocket, hClientSocket
invoke WSACloseEvent, hClientEvent
jmp @DoListen
@CheckServerClose:
test WSAEventListen.lNetworkEvents, FD_CLOSE
jz @DoListen
;do server close
invoke closesocket, hListenSocket
invoke WSACloseEvent, hListenEvent
mov eax, 1
ret
ListenProc endp
Posted on 2002-12-25 02:38:11 by Yanda
invoke htons, szPort
I don't know what your szPort var looks like but the 'sz' prefix is normally used for null terminated string pointers. You should use an immediate value here, not a string. If szPort is just a dword it's okay too.
mov hListenEvent, eax
mov [pListenEvent], eax
Not really a problem but those two instructions do exactly the same (but with different vars). Using a variable name with brackets or without is both the same. So pListenEvent will not contain a pointer to anything, it will just hold the same value as hListenEvent. Even if you could store a pointer this way, what should it point to? You can't point to eax...
invoke WSAWaitForMultipleEvents, 1, addr pListenEvent, FALSE, INFINITE, FALSE
Change the 'addr pListenEvent' to 'addr hListenEvent', and you can remove the pListenEvent var. As your code is right now, both do the same thing and it works because pListenEvent isn't really a pointer.. If pListenEvent really were a pointer to an event this would be even wrong, since you would get a pointer to a pointer to an event handle then (addr of a pointer).
The same thing goes for hClientEvent/pClientEvent.
invoke accept, hListenSocket, addr SA_IN, SIZEOF SA_IN
The last parameter should be a pointer to a variable holding the size of sockaddr_in, not the size itself:
mov saSize, sizeof SA_IN
invoke accept, hListenSocket, addr SA_IN, addr saSize
The last one should be the main problem.
Thomas
alrite:alright: Thomas!
thankx alots, let me try to fix it.
yanda,
thankx alots, let me try to fix it.
yanda,