|
-
Sep 14th, 2001, 02:20 PM
#1
Thread Starter
New Member
Why won't this work in non-blocking mode??
If I take out the ioctlsocket bit which makes the socket non-blocking it works fine. If I leave it in, it only collects some of the data which u can see in the bleh.txt file. Why does it not work when its in non-blocking mode?? Also if I try this code on some other url's without the non-blocking mode it collects all the data to the file but the newline character doesn't take effect in some places.
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\wsock32.inc
includelib \masm32\lib\wsock32.lib
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include C:\ASM\string.inc
.data
SOCKSET STRUCT
dwCount dword ?
dwSocket dword ?
SOCKSET ENDS
wsadata WSADATA <?>
fdset SOCKSET <?>
timeout timeval <?>
p sockaddr_in <?>
sock dword ?
sockopt dword 1
recbuf byte 1001 dup (0)
stobuf byte 64000 dup (0)
port dword 80, 0
ipaddress byte "216.17.149.78", 0
slcterror1 byte "select error: write", 0
slcterror2 byte "select error: read", 0
nosend byte "couldn't send data", 0
blockerror byte "couldn't set socket mode", 0
noinit byte "couldn't initialise winsock", 0, 100 dup (0)
nosock byte "couldn't create a socket", 0
noconnect byte "couldn't connect to server", 0
closed byte "connection closed", 0
finished byte "FINISHED", 0
filename byte "bleh.txt", 0
bufwrite dword ?
get byte 'GET /index.html', 10, 13
byte 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*', 10, 13
byte 'Accept-Language: en-gb', 10, 13
byte 'Accept-Encoding: gzip, deflate', 10, 13
byte 'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)', 10, 13
byte 'Host: www.rec.com', 10, 13
byte 'Connection: Keep-Alive', 10, 13, 10, 13, 0 ;258 chars
;=========
.code
start:
@@initialise_winsock:
invoke WSAStartup, 101h, addr wsadata
cmp eax, NULL
jne @@noinit
@@setup_socket:
invoke socket, AF_INET, SOCK_STREAM, 0
cmp eax, INVALID_SOCKET
je @@nosock
mov [sock], eax
invoke htons, 80
mov p.sin_port, ax
invoke inet_addr, addr ipaddress
mov p.sin_addr, eax
mov p.sin_family, AF_INET
@@connect_to_server:
invoke connect, [sock], addr p, sizeof p
cmp eax, SOCKET_ERROR
je @@noconnect
@@make_non_blocking:
invoke ioctlsocket, [sock], FIONBIO, addr sockopt
cmp eax, SOCKET_ERROR
je @@blockerror
@@check_for_sock_write:
mov eax, [sock]
mov fdset.dwSocket, eax
mov fdset.dwCount, 1
mov timeout.tv_sec, 3
mov timeout.tv_usec, NULL
invoke select, NULL, NULL, addr fdset, NULL, addr timeout
cmp eax, NULL
je @@slcterror1
cmp eax, SOCKET_ERROR
je @@slcterror1
@@send_request_data:
invoke lstrlen, addr get
invoke send, [sock], addr get, eax, NULL
cmp eax, SOCKET_ERROR
je @@no_send
@@check_for_sock_read:
mov eax, [sock]
mov fdset.dwSocket, eax
mov fdset.dwCount, 1
mov timeout.tv_sec, 20
mov timeout.tv_usec, NULL
invoke select, NULL, addr fdset, NULL, NULL, addr timeout
cmp eax, NULL
je @@slcterror2
cmp eax, SOCKET_ERROR
je @@slcterror2
@@receive_data_loop:
invoke recv, [sock], addr recbuf, 1000, NULL
cmp eax, SOCKET_ERROR
je @@closed
cmp eax, NULL
je @@closed
mov byte ptr [recbuf+eax], 0
invoke _strncat, addr stobuf, addr recbuf, eax ; my append-a-string proc
jmp @@receive_data_loop
@@closed:
invoke MessageBox, NULL, addr closed, addr finished, MB_OK
invoke closesocket, [sock]
invoke WSACleanup
invoke CreateFile,\
addr filename,\
GENERIC_WRITE,\
FILE_SHARE_READ or\
FILE_SHARE_WRITE,\
NULL,\
CREATE_ALWAYS,\
FILE_ATTRIBUTE_NORMAL,\
NULL
push eax
invoke lstrlen, addr stobuf
mov edx, eax
pop eax
invoke WriteFile,\
eax,\
addr stobuf,\
edx,\
addr bufwrite,\
NULL
invoke MessageBox, NULL, addr stobuf, addr finished, MB_OK
jmp @@exitproc
;==============
@@no_send:
invoke MessageBox, NULL, addr nosend, NULL, MB_OK
jmp @@exitproc
@@blockerror:
invoke MessageBox, NULL, addr blockerror, NULL, MB_OK
jmp @@exitproc
@@slcterror1:
invoke MessageBox, NULL, addr slcterror1, NULL, MB_OK
jmp @@exitproc
@@slcterror2:
invoke MessageBox, NULL, addr slcterror2, NULL, MB_OK
jmp @@exitproc
@@nosock:
invoke MessageBox, NULL, addr nosock, NULL, MB_OK
jmp @@exitproc
@@noinit:
invoke MessageBox, NULL, addr noinit, NULL, MB_OK
jmp @@exitproc
@@noconnect:
invoke MessageBox, NULL, addr noconnect, NULL, MB_OK
@@exitproc:
invoke ExitProcess, 1
end start
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|