News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

set wsock connect() timeout

Started by Ghirai, May 04, 2007, 11:24:03 AM

Previous topic - Next topic

Ghirai

Is there any way i can set a timeout for connect(), without using SetTimer (because i don't have any windows)?
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

Tedd

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?
No snowflake in an avalanche feels responsible.

ecube

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

Ghirai

MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

Tedd

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 ...... ::)

No snowflake in an avalanche feels responsible.

Tedd

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?
No snowflake in an avalanche feels responsible.