Hello,

Sorry for a bit silly question. But, how can I disconnect a socket in win32 asm?

I need to get HTTP 'GET' reply. And I only need the header. As i understood the only way is to send request for an object and then disconnect the socket after the header is received, but prior to any other data is sent. So the code looks something like:



msg PROC hWind :DWORD,uMsg :DWORD,wParam :DWORD,lParam :DWORD


..........

.elseif uMsg == WM_SOCK
mov eax, lParam

.if ax == FD_CONNECT
invoke send, sock, addr send_http_get, send_http_get_size, 0

.elseif lParam == FD_READ

invoke ioctlsocket, sock, FIONREAD, ADDR ssize
invoke recv, sock, buffer, ssize, 0

; the header has been received, so i close the socket

invoke closesocket, sock

.elseif lParam == FD_CLOSE

.endif

................

New_msg ENDP

connect PROC

invoke WSAAsyncSelect,sock,hWin,WM_SOC, FD_CONNECT or FD_READ or FD_CLOSE
invoke connect,sock, addr socketstr, sizeof socketstr

connect ENDP


However for some reason closing the socket doesn't work for me... the FD_READ continues to repeat till the end of full data.
Posted on 2004-09-06 06:40:53 by trewq
I saw your problem...

Try to put


invoke ioctlsocket, sock, FIONREAD, ADDR ssize
invoke recv, sock, buffer, ssize, 0
invoke closesocket, sock


in a thread....
instruction closesocket must be outside Message--->WM_SOCK if not it is impossible for it to return before to be out...

I think you you will be happy...to see that your message are read ...

Please go and see ---->http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/using_winsock.asp

Gerard--
-----------
Posted on 2004-09-06 08:21:47 by gerard
thanks.
i didn't knew about problem of calling closesocket within window message loop.
Posted on 2004-09-07 05:46:46 by trewq