Is there any way i can set a timeout for connect(), without using SetTimer (because i don't have any windows)?
The connection attempt will eventually timeout itself, but I don't see a way to control how long this should be - ultimately it's down to winsock, but depends on network conditions and whether any reply at all is received from the host, etc.
Create a separate thread and have it check the time passed?
found in some source
TimeOut proto :DWORD,:DWORD
SO_RCVTIMEO equ 1006h
SO_SNDTIMEO equ 1005h
.data
IOTimeOut dd 0
.code
TimeOut PROC sock:DWORD, milliseconds:DWORD
;
; Set the timeout for sending and recieving data
;
mov eax, milliseconds
mov IOTimeOut, eax
invoke setsockopt, sock, SOL_SOCKET, SO_RCVTIMEO, addr IOTimeOut, 4 ;recv
invoke setsockopt, sock, SOL_SOCKET, SO_SNDTIMEO, addr IOTimeOut, 4 ;send
ret
TimeOut ENDP
Thanks :bg
I did see those, but..
Quote
BSD options not supported for setsockopt are shown in the following table.
SO_ACCEPTCONN BOOL Socket is listening.
SO_RCVLOWAT int Receives low watermark.
SO_RCVTIMEO int Receives time-out in milliseconds (available in the Microsoft implementation of Windows Sockets 2).
SO_SNDLOWAT int Sends low watermark.
SO_SNDTIMEO int Sends time-out in milliseconds (available in the Microsoft implementation of Windows Sockets 2).
SO_TYPE int Type of the socket.
So make sure you specify version 2 in WSAStartup :wink
Also, be careful fiddling with those values - they will affect all sending and receiving (which includes all of the extra tcp packets to keep the connection open, etc) - so you might want to get the values first and then replace them upon connection. Also, due to the send-receive-send cycle of tcp connection negotiation, you can only effect the connection timeout in a roundabout way, it still depends on retries and acknowledgements, and ...... ::)
Just found SetWaitableTimer - which is much better than SetTimer (IMHO) and you don't need a window as it uses events not messages.
Might be a better solution than playing with critical timings?