Sign in to follow this  
Followers 0
kylomas

inetgetinfo, inetgetsize and inetclose returing unexpected results

8 posts in this topic

Hi Experts,

I have a function that I call once for each member of an array. That function is supposed to do a background inetget, update a size field (gui), update a progress bar (gui) and write a file. The progress bar and size fields are being updated intermittently. The file is always output correctly. Following is some code that I've marked up with symptoms. The two questions that I have are:

1 - The files that I am downloading are avg 80KB. The progress bar frequently show no updating and the size

field often shows "0". Both of these symptoms are intermittent and, so far, not predictable. I've dumped

the results of the % calc for the progress bar and often get a negative number (something else is failing

to cause this). This is a Win/XP SP3 system. Is what I am expecting possible?

2 - INETCLOSE always returns "false". I've also noticed that after successive runs I get

internet activity when I am not expecting any. The doc indicates that this is a failure but does not give

any remedial action, or, even what might be causing the failure. What, exactly, does a return of "false"

mean?

Please consider this a "back burner" type issue as the progress bar and size fields are eye-catchers for my users. The output file is always written correctly so there is no loss of functionality (just causing my

frustration/curiosity levels to peak).

If you have any other comments on the code (style/technique or otherwise) I would appreciate your comments as I am relatively new to the wonderful world of Windows.

Thanks,

kylomas

func getter($in,$out)

local $s = inetgetsize($in,1) <---- this frequently returns 0

if $s = 0 and @error <> 0 then

$msg1 = msgbox(17,'INETGETSIZE ERROR','Error = ' & @error)

if $msg1 = 2 then exit

endif

guictrlsetdata($p2,$s & ' bytes total')

$g = InetGet($in,$out, 1, 1)

Do

local $getstat = inetgetinfo($g,0) <---- this frequently returns 0

GUICtrlSetData($p1, Ceiling(($getstat/$s)*100)) <---- this is updating intermittently

Until InetGetInfo($g, 2)

local $closecnt = 0

do

$closecnt = $closecnt + 1

if $closecnt > 100 then

lf('inetclose count exceeded')

Exit

EndIf

until inetclose($g) <---- This is returning "false"

endfunc


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Please use the AutoIt tags to insert code. Click the blue icon below Bold and Add. Then paste your code between the markups.

I don't have exactly the same needs as you, but FYI here's an amended extract of the code I use, which runs hundreds to thousands times a day. My issue is only with the site responding very slowly at times, or not at all. Hence the retry loop, which you could spare entirely.

Local $TmpFile = _TempFile(@TempDir, '~foobar~', '.html', 20)
    Local $timer, $hInet, $status
    For $retry = 1 to 10
        $timer = TimerInit()
        $hInet = InetGet($url, $TmpFile, 17, 1)     ; background direct download no cache
        Do
            Sleep(50)
            $status = InetGetInfo($hInet, -1)
            If $status[2] Then ExitLoop                         ; download is complete
        Until TimerDiff($timer) >= 20000                        ; allow 20s for download
        InetClose($hInet)                                       ; free handle
        If $status[3] Then                                      ; download is said successful

    ; here I want to check that the download contents loks like valid before further processing
            $texteSuivi = FileRead($TmpFile)
            $str = StringRight($texteSuivi, 10)
            If StringRegExp($str, "(\}\s*){4}", 0) Then         ; on s'assure que la page a été reçue en intégralité
                ExitLoop
            EndIf
        Else
            ConsoleWrite("Host didn't answer within reasonable time." & @LF)
        EndIf
    Next
    FileDelete($TmpFile)
    If $retry > 10 Then
        _WarnBox("Host is down or another major issue gets in the way!")    ; this is a derived MsgBox
        Return 1
    EndIf

Try it, just as a test for your case.

In your code, you should put Sleep(100) in the status poll loop, and allow for few first returns to give 0 result: that seem to mean the site didn't answer yet. Also the size is optional: a site might never return it, without breaking rules, so you shouldn't rely on it that much. If you know your files will be below 100Kb, then init your size variable to 100K and try to get a valid size from the site. If it does send back, say, 71458, then it's probably the right file size, but if it always send back 0, then doing this way will make your progress bar show something more or less close to reality without risk of zero divide.

Finally, try working with the 'complete' and 'successful' status entries to determine when the thing is done rather than InetClose returning <> 0. Remember, your tight loops will be very fast compared to a background download, leave the site some time to start doing things!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Mass Spammer,

Thanks for the prompt reply...I thought it might be a timing issue all along...any thoughts on why inetclose is returning "false"...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Mass Spammer,

Thanks for the prompt reply...I thought it might be a timing issue all along...any thoughts on why inetclose is returning "false"...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jhcd, sorry (called you Mass Spammer)

I really, really, really suck at these forums !!!!

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jchd,

Let me see if I understand your code...you are using a background xfer because the target might not be responding, correct?

Also, is there some advantage/difference to using the array returned by inetgetinfo as opposed to boolean type testing... e.g.

Until InetGetInfo($g, 2)
?

Thanks,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jhcd, sorry (called you Mass Spammer)

I really, really, really suck at these forums !!!!

A bit more than you think: jchd :mellow:

Forget it, no harm done!

Try my own poor code and look if all goes as you expect. I hope so.

InetClose: I've no good idea. Insert a ConsoleWrite in the code to trace it.

Jean-Christophe (5:00 AM --> sleep needed).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Bon nuit !!!!


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0