_INetGetSource - Timeout

  • Hi,

    Ich frage von einem embedded WebServer via _INetGetSource XML Daten ab.

    Wenn der Server gleichzeitig viele Anfragen von anderer Stelle bekommt, ist die Antwortzeit ziemlich lange, kann bis zu 30 Sekunden dauern biss dann _INetGetSource die Schnauze voll hat und abbricht. in dieser Zeit ist aber mein Script blockiert. Kenn jemand eine Lösung wie man die Anfrage vorzeitig abbrechen, oder das anders lösen kann?

    TCPTimeout zu setzen bringt an der stelle nichts.

    Danke schon mal und Gruß Rabbit

    Einmal editiert, zuletzt von rabbit (17. April 2008 um 10:45)

  • Vllt so: (ungetestet)

    Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ;
    ; Function Name: _INetGetSourceTimeOut()
    ; Description: Gets the source from an URL without writing a temp file.
    ; Parameter(s): $s_URL = The URL of the site.
    ; Requirement(s): DllCall/Struct & WinInet.dll
    ; Return Value(s): On Success - Returns the source code.
    ; On Failure - 0 and sets @ERROR = 1
    ; Author(s): Wouter van Kesteren.
    ;
    ;===============================================================================
    Func _INetGetSource($s_URL, $s_Header = '',$TimeOut = 0xFFFFFF)

    If StringLeft($s_URL, 7) <> 'http://' And StringLeft($s_URL, 8) <> 'https://' Then $s_URL = 'http://' & $s_URL

    Local $h_DLL = DllOpen("wininet.dll")

    Local $ai_IRF, $s_Buf = ''

    Local $ai_IO = DllCall($h_DLL, 'int', 'InternetOpen', 'str', "AutoIt v3", 'int', 0, 'int', 0, 'int', 0, 'int', 0)
    If @error Or $ai_IO[0] = 0 Then
    DllClose($h_DLL)
    SetError(1)
    Return ""
    EndIf

    Local $INTERNET_OPTION_CONNECT_TIMEOUT = 2
    Local $INTERNET_OPTION_RECEIVE_TIMEOUT = 6
    Local $time = DllStructCreate("long")
    DllStructSetData($time,1,$TimeOut)
    Local $ai_IO = DllCall($h_DLL, 'int', 'InternetSetOption', 'int', $ai_IO[0], 'dword', $INTERNET_OPTION_CONNECT_TIMEOUT,"ptr",DllStructGetPtr($time),"dword",DllStructGetSize($time))
    If @error Or $ai_IO[0] = 0 Then
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
    DllClose($h_DLL)
    SetError(1)
    Return ""
    EndIf
    Local $ai_IO = DllCall($h_DLL, 'int', 'InternetSetOption', 'int', $ai_IO[0], 'dword', $INTERNET_OPTION_RECEIVE_TIMEOUT,"ptr",DllStructGetPtr($time),"dword",DllStructGetSize($time))
    If @error Or $ai_IO[0] = 0 Then
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
    DllClose($h_DLL)
    SetError(1)
    Return ""
    EndIf

    Local $ai_IOU = DllCall($h_DLL, 'int', 'InternetOpenUrl', 'int', $ai_IO[0], 'str', $s_URL, 'str', $s_Header, 'int', StringLen($s_Header), 'int', 0x80000000, 'int', 0)
    If @error Or $ai_IOU[0] = 0 Then
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
    DllClose($h_DLL)
    SetError(1)
    Return ""
    EndIf

    Local $v_Struct = DllStructCreate('udword')
    DllStructSetData($v_Struct, 1, 1)

    While DllStructGetData($v_Struct, 1) <> 0
    $ai_IRF = DllCall($h_DLL, 'int', 'InternetReadFile', 'int', $ai_IOU[0], 'str', '', 'int', 256, 'ptr', DllStructGetPtr($v_Struct))
    $s_Buf &= StringLeft($ai_IRF[2], DllStructGetData($v_Struct, 1))
    WEnd

    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IOU[0])
    DllCall($h_DLL, 'int', 'InternetCloseHandle', 'int', $ai_IO[0])
    DllClose($h_DLL)
    Return $s_Buf
    EndFunc ;==>_INetGetSourceTimeOut

    [/autoit]

  • Hi,

    danke scheint zu funtionieren, habe zwar momentan das Gerät nicht bei mir, aber am lokalen Webserver ändert sich das Zeitverhalten, wenn ich die Timeout Zeit verändere. Musste aber noch eine kleinigkeit ändern.

    Local $ai_IOCTO = DllCall($h_DLL, 'int', 'InternetSetOption', 'int', $ai_IO[0], 'dword', $INTERNET_OPTION_CONNECT_TIMEOUT,"ptr",DllStructGetPtr($time),"dword",DllStructGetSize($time))
    If @error Or $ai_IOCTO[0] = 0 Then


    Local $ai_IORTO = DllCall($h_DLL, 'int', 'InternetSetOption', 'int', $ai_IO[0], 'dword', $INTERNET_OPTION_RECEIVE_TIMEOUT,"ptr",DllStructGetPtr($time),"dword",DllStructGetSize($time))
    If @error Or $ai_IORTO[0] = 0 Then


    ich habe die funktion jetzt zusätzlich mit reingebastelt, damit ich auch die bisherige Funktion weiterverwenden kann, Timeout setze ich nicht fest sondern übergebe als Parameter.


    Gruß rabbit