Jump to content
Professor_Bernd

InetClose() always returns False

Recommended Posts

InetClose

Return Value

True: if the handle was found and closed.
False: if not.

Remarks

InetGet() handles must be closed or resources will leak.
Closing the handle to a download still in progress will cancel the download.

 

I have tried many things, I have successfully run downloads, I have aborted downloads, but InetClose() always returns False. Am I doing something wrong?

As a simple example for testing here is the example from the AutoIt help, plus ConsoleWrite() for returning InetClose().

#include <InetConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
    ; Save the downloaded file to the temporary folder.
    Local $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Download the file in the background with the selected option of 'force a reload from the remote site.'
    Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

    ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True.
    Do
        Sleep(250)
    Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)

    ; Retrieve the number of total bytes received and the filesize.
    Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD)
    Local $iFileSize = FileGetSize($sFilePath)

    ; Close the handle returned by InetGet.
;     InetClose($hDownload)
    ConsoleWrite("InetClose($hDownload): " & InetClose($hDownload) & @CRLF)  ; <== Show the return value of InetClose().

    ; Display details about the total number of bytes read and the filesize.
    MsgBox($MB_SYSTEMMODAL, "", "The total download size: " & $iBytesSize & @CRLF & _
            "The total filesize: " & $iFileSize)

    ; Delete the file.
    FileDelete($sFilePath)
EndFunc   ;==>Example

 

If someone wants to test with other files, here are download Test Files in different sizes.

Edited by Professor_Bernd

Share this post


Link to post
Share on other sites

I do not know if it is the right explanation.  I tried to abort a DL and it is still returning False.

Edited by Nine

Share this post


Link to post
Share on other sites

It always returns False for me too.
2 trac tickets (at least) have already been created :
* Trac ticket #2284 rejected by Jon 7 years ago
* Trac ticket #3659 which looks more promising, initiated by Tersion & mikell 2 years ago in this link, now owned by jpm who sent a fix to Jon 4 months ago.

Fingers crossed...

Share this post


Link to post
Share on other sites

This is very interesting! Thank you both for this informative information!

Interesting is also the information,

  • that the problem has been known for 10 years,
  • that 7 years ago a ticket was created that was rejected without explanation
  • that 2 years ago a ticket was issued again,
  • that only 4 months ago there was a reaction with a proposal to fix the problem,
  • that I hadn't used the forum search this time, and there was a thread with almost identical title. :whistle:

Ok, based on this info I think it was not my fault that InetColse() always returned False and that a solution is unfortunately NOT in sight!

Therefore the following important questions:

  • Does the problem have anything to do with $INET_DOWNLOADBACKGROUND? (My script needs this setting to show progress.)
  • Does InetClose() abort a download even if False is returned?
  • How can I determine if a download was aborted?
  • And finally: What problems can I expect if my script is closed and the download handle is NOT closed?

Share this post


Link to post
Share on other sites
2 minutes ago, Professor_Bernd said:

Does InetClose() abort a download even if False is returned?

Yes it does, tested.

2 minutes ago, Professor_Bernd said:

How can I determine if a download was aborted?

File size would be smaller than InetGetSize.

3 minutes ago, Professor_Bernd said:

What problems can I expect if my script is closed and the download handle is NOT closed?

Memory leak (based on help file).

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:
  • "How can I determine if a download was aborted?"

File size would be smaller than InetGetSize.

This probably won't work if a download hangs, but I think in the other 99% of cases a user will want to cancel a download because it takes too long or the user decided otherwise. So I see your answer as a good workaround.

 

1 hour ago, Nine said:
  • "What problems can I expect if my script is closed and the download handle is NOT closed?"

Memory leak (based on help file).

How can you detect a memory leak without studying rocket science first? ;)

 

1 hour ago, Nine said:
  • "Does InetClose() abort a download even if False is returned?"

Yes it does, tested.

Thanks for testing! I think you can get over the incorrect return of InetClose(), the most important point is that InetClose() works.

My script has a cancel button for the download. But when the user clicks on the close button of the GUI (formerly red X button), the download should be closed before the GUI is closed. With your information I will now simply perform an InetClose() in the OnClose of the GUI.

Thanks a lot to both of you for your useful information! 👍

Share this post


Link to post
Share on other sites
18 minutes ago, Professor_Bernd said:

How can you detect a memory leak

Task manager will tell.  If a process is continuously increasing its memory usage, you can assume that there is a memory leak (especially with AutoIt script, I never seen a case where it keeps increasing it memory on purpose).

Share this post


Link to post
Share on other sites

Not always unfortunately.  If you find a process that suffers memory leak, you need to go into Task Manager and now look also at the system memory before and after script closes.  If all the process memory is recuperated then it is fine, otherwise, you just probably found yourself a serious bug...

Share this post


Link to post
Share on other sites
9 minutes ago, Nine said:

If all the process memory is recuperated then it is fine, otherwise, you just probably found yourself a serious bug...

Oh no! Good thing I have a good insect spray. :muttley:

Seriously: Thanks for your info!

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...