找回密码
 加入
搜索
查看: 7756|回复: 5

[网络通信] 求助,为什么InetClose关闭不了,释放不了

  [复制链接]
发表于 2014-8-23 23:32:21 | 显示全部楼层 |阅读模式
本帖最后由 siton 于 2014-8-23 23:37 编辑

大神求助。。关闭的时候返回false。关闭不了,释放不了网络资源,
InetClose
关闭 InetGet() 返回的句柄.

InetClose ( 句柄 )
参 数
句柄 由 InetGet() 返回的句柄.

返 回 值
返回 True: 句柄找到并关闭.
返回 False: 不是.

备 注
InetGet() 句柄必须关闭, 不然残留资源不会释放.

后台下载,要关闭,。。。555555555555 ,。。怎么办?
不然会消耗资源得不到释放啊。
#include <INet.au3>
#include <InetConstants.au3>
Global $ff = 0
Global $FachBackStr
Global        $feachStr
$FURL="http://www.22feng.com/message.mp3"
                $feachStr = InetGet($FURL,@ScriptDir & "/temp/" &$ff&"--"&RandomSTR(6) & ".mp3",1, 1) ;取码
                        ConsoleWrite("第一次下载开始:"&@CRLF)
                        ConsoleWrite(@ScriptDir & "/temp/" & $ff & ".mp3")
While 1
        Local $STR, $ErrString, $TSTR
        ;取码

                $FachBackStr = InetGetInfo($feachStr, $INET_DOWNLOADCOMPLETE )        
                
                If $FachBackStr = True Then ; 如果取码数据下载完成
                        $ff = $ff + 1
                        ConsoleWrite("下载成功!"&@CRLF)
                        $CLOSEH=InetClose($feachStr)
                        ConsoleWrite("关闭下载句柄:"&$CLOSEH&@CRLF)
                        $feachStr = InetGet($FURL,@ScriptDir & "/temp/" &$ff&"--"&RandomSTR(6) & ".mp3", 1, 1) ;取码
                Elseif $FachBackStr = False  Then
                        ConsoleWrite("下载中!"&$feachStr&@CRLF)                
                EndIf
                Sleep(500)
WEnd


Func RandomSTR($Lenth);随机字符串
        Local $STR = "0123456789abcdefghijklmnopqrstuvwxyz"
        ;$Lenth = Random(6, 10, 1)
        Local $key = ""
        For $i = 1 To $Lenth
                $key = $key & StringMid($STR, Random(1, 36, 1), 1)
        Next
        Return ($key)
EndFunc   ;==>RandomSTR
发表于 2014-8-24 12:04:55 | 显示全部楼层
哥们,我试了一下,你这个应该是没问题的。对于官网的例子也存在该问题。
#include <InetConstants.au3>
#include <MsgBoxConstants.au3>

; Download a file in the background.
; Wait for the download to complete.

Example()

Func Example()
    ; Save the downloaded file to the temporary folder.
    Local $sFilePath = @TempDir & "\update.dat"

    ; 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", @TempDir & "\update.dat", $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.
    ConsoleWrite("download:" & InetClose($hDownload))

    ; 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
在这个例子中,ConsoleWrite("download:" & InetClose($hDownload))

也会返回false。
 楼主| 发表于 2014-8-24 17:16:57 | 显示全部楼层
谢谢楼上的哥们。

我用官方帮助里提供的例子也是返回 FALSE 确实是这样,

到底是不是释放资源了呢。。郁闷。

如果释放了,那倒是没啥的关系啦。
发表于 2014-8-25 09:28:55 | 显示全部楼层
回复 3# siton


    如果你想继续追寻这个问题的 root cause, 可以去查API,自己亲自实现,看下是不是AU3的bug。
 楼主| 发表于 2014-8-25 22:12:03 | 显示全部楼层
我新手, root cause 是什么玩意,不懂。。
发表于 2014-8-30 16:48:50 | 显示全部楼层
回复 5# siton


    就是问题的根本原因。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-23 22:17 , Processed in 0.080004 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表