Jump to content

Question about InetGet handles


Quinch
 Share

Recommended Posts

Namely, how does passing a InetGet handle work when downloading in the background is involved? So if I'm downloading fifty files simultaneously, what will the handle return? Also, if I'm not actually using it for actual information, do I need to open an InetGet handle to begin with? The help file mentions a resource leak if the handle is not closed, but doesn't elaborate on a situation if it's not opened to begin with.

Link to comment
Share on other sites

Namely, how does passing a InetGet handle work when downloading in the background is involved? So if I'm downloading fifty files simultaneously, what will the handle return? Also, if I'm not actually using it for actual information, do I need to open an InetGet handle to begin with? The help file mentions a resource leak if the handle is not closed, but doesn't elaborate on a situation if it's not opened to begin with.

EDITED.

It's not described fairly well in the help so I assume you didn't understand it. I'm not sure I did reading it again.

This is what I think it means on my second attempt but I'll come back later after testing it.

A handle is returned by the InetGet function whether you set the background parameter to 1 or not. You must close the handle with InetClose($handle) when you no longer need it or at least before you close your script.

If you set th ebackground parameter to 1 then the handle can be used to check the progress of the download

To see how the download is getting on for a certain file you simply use the correct handle-

$InfoForFile4 = InetGetInfo($handle4)

If background is notset to 1 then th efunction only eturns a handle when th edownload is complete. In this case the handle can be used to detrmine the success of the download using

InetGetInfo($Handle)

The help needs to be corrected for InetGet.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Ouch - does that mean that I need to open and close an InetGet handle for each and every file I download in the background? If so, what would be the best way to handle that if you're downloading hundreds or thousands of files? Slap the handles into an array or something?

Edited by Quinch
Link to comment
Share on other sites

Ouch - does that mean that I need to open and close the InetGet handle for each and every file I download in the background? If so, what would be the best way to handle that if you're downloading hundreds or thousands of files? Slap the handles into an array or something?

I completely changed my post so you had better read it again; I didn't think you would be so fast!

But yes, if there is more than 1 then I would always consider using an array.

Const $NumUrls = 1000
dim $urls[$NumUrls]
dim $InetHandle[$NumUrls]
Dim $Infos[$NumUrls]

for $n = 0 to $NumUrls - 1
$inetHandles = InetGet(......,1)
next

for $n = 0 to $NumUrls - 1
$infos[$n] = InetGetInfo($inetHandles[$n]
next

...

for $n = 0 to $NumUrls - 1
InetClose($inetHandles[$n]
next
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Quinch,

Doing something similar only with sports stats. The reason that I'm asking is that some cites may have a "flood" type of control to throttle traffic. When I first got my app running I scraped several years worth of data (3500-4500 files) with no problems.

Good Luck,

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

Link to comment
Share on other sites

Ah, yeah, that was my first theory too, but that wasn't the case. Either way, taking care to open/close InetGet handles after each thread seems to have solved the problem.

{looks at the thread counter}

Or at the very least the script is taking longer to die than before. The day is young.

Link to comment
Share on other sites

Are you guys using another helpfile than I am?

Success:

The return value changes depending on if the download is in the background:

Background: A handle is returned. The handle can be used with InetGetInfo(). The handle must be closed with InetClose().

Wait: The number of bytes downloaded.

Failure:

Background: A handle is returned. To determine if there was an error with the download, use InetGetInfo(). The handle must be closed with InetClose().

Wait: Sets @error to non-zero and returns 0.

If you use a background download you will get a handle that you must close. It can't get clearer any than this!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...