initial checkin of TclCurl
This commit is contained in:
31
tests/multi/auto.tcl
Executable file
31
tests/multi/auto.tcl
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/local/bin/wish8.4
|
||||
|
||||
package require TclCurl
|
||||
|
||||
#wm withdraw .
|
||||
|
||||
proc CleanUp {multiHandle easyHandle} {
|
||||
puts "\n\nCleaning up\n\n"
|
||||
|
||||
$::multiHandle removehandle $::easyHandle
|
||||
$::multiHandle cleanup
|
||||
$::easyHandle cleanup
|
||||
|
||||
puts "\n\nAll done\n\n"
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
set multiHandle [curl::multiinit]
|
||||
set easyHandle [curl::init]
|
||||
|
||||
$easyHandle configure -url http://127.0.0.1/~andres/HomePage.tar.gz -file home.tar.gz
|
||||
|
||||
$multiHandle addhandle $easyHandle
|
||||
|
||||
puts "Starting transfer..."
|
||||
|
||||
$multiHandle auto -command "CleanUp $multiHandle $easyHandle"
|
||||
|
||||
|
||||
|
31
tests/multi/autoGUI.tcl
Executable file
31
tests/multi/autoGUI.tcl
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/local/bin/wish8.4
|
||||
|
||||
package require TclCurl
|
||||
|
||||
proc CleanUp {multiHandle easyHandle} {
|
||||
puts "\n\nCleaning up $multiHandle - $easyHandle\n\n"
|
||||
|
||||
$multiHandle removehandle $easyHandle
|
||||
$multiHandle cleanup
|
||||
$easyHandle cleanup
|
||||
|
||||
puts "\n\nAll done\n\n"
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
proc StartTransfer {} {
|
||||
set multiHandle [curl::multiinit]
|
||||
set easyHandle [curl::init]
|
||||
|
||||
$easyHandle configure -url http://127.0.0.1/~andres/HomePage.tar.gz -file home.tar.gz
|
||||
|
||||
$multiHandle addhandle $easyHandle
|
||||
|
||||
$multiHandle auto -command "CleanUp $multiHandle $easyHandle"
|
||||
}
|
||||
|
||||
set start [button .start -text Start -command StartTransfer]
|
||||
set stop [button .stop -text Stop -command StopTransfer]
|
||||
|
||||
pack $start $stop -side left -padx 10 -pady 10
|
80
tests/multi/cancelTrans.tcl
Executable file
80
tests/multi/cancelTrans.tcl
Executable file
@ -0,0 +1,80 @@
|
||||
#!/usr/local/bin/wish8.4
|
||||
|
||||
package require TclCurl
|
||||
|
||||
proc ProgressCallback {dltotal dlnow ultotal ulnow} {
|
||||
|
||||
set dltotal [expr round($dltotal)]
|
||||
set dlnow [expr round($dlnow)]
|
||||
set ultotal [expr round($ultotal)]
|
||||
set ulnow [expr round($ulnow)]
|
||||
|
||||
puts "Progress callback: $dltotal - $dlnow - $ultotal - $ulnow"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
proc Perform {multiHandle} {
|
||||
if {[catch {$multiHandle active} activeTransfers]} {
|
||||
puts "Error checking active transfers: $activeTransfers"
|
||||
return -1
|
||||
}
|
||||
|
||||
if {[catch {$multiHandle perform} running]} {
|
||||
puts "Error: $running"
|
||||
return -1
|
||||
}
|
||||
return $running
|
||||
}
|
||||
|
||||
proc Transfer {multiHandle easyHandle} {
|
||||
global eventId
|
||||
set runningTransfers [Perform $multiHandle]
|
||||
if {$runningTransfers>0} {
|
||||
set eventId [after 200 "Transfer $multiHandle $easyHandle"]
|
||||
} else {
|
||||
puts "Were are done, cleaning up..."
|
||||
$multiHandle removehandle $easyHandle
|
||||
$easyHandle cleanup
|
||||
$multiHandle cleanup
|
||||
puts "All done"
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
proc StartTransfer {} {
|
||||
|
||||
set curlEasyHandle [curl::init]
|
||||
|
||||
$curlEasyHandle configure -url "127.0.0.1/~andres/cosa&co.tar" \
|
||||
-canceltransvarname cancel -progressproc ProgressCallback\
|
||||
-file cosa.tar -noprogress 0
|
||||
|
||||
set curlMultiHandle [curl::multiinit]
|
||||
$curlMultiHandle addhandle $curlEasyHandle
|
||||
|
||||
after 100 "Transfer $curlMultiHandle $curlEasyHandle"
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
proc StopTransfer {} {
|
||||
global cancel eventId
|
||||
|
||||
puts "The download has been cancelled"
|
||||
|
||||
set cancel 1
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
set start [button .start -text Start -command StartTransfer]
|
||||
set stop [button .stop -text Stop -command StopTransfer]
|
||||
|
||||
pack $start $stop -side left -padx 10 -pady 10
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
57
tests/multi/double.tcl
Executable file
57
tests/multi/double.tcl
Executable file
@ -0,0 +1,57 @@
|
||||
package require TclCurl
|
||||
|
||||
|
||||
proc Perform {multiHandle} {
|
||||
if {[catch {$multiHandle active} activeTransfers]} {
|
||||
puts "Error checking active transfers: $activeTransfers"
|
||||
return -1
|
||||
}
|
||||
if {[catch {$multiHandle perform} running]} {
|
||||
puts "Error: $running"
|
||||
return 1
|
||||
}
|
||||
return $running
|
||||
}
|
||||
|
||||
proc StartTransfer {multiHandle} {
|
||||
while {1==1} {
|
||||
set runningTransfers [Perform $multiHandle]
|
||||
if {$runningTransfers>0} {
|
||||
after 500
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
puts "We create and configure the easy handles"
|
||||
|
||||
set curlEasyHandle1 [curl::init]
|
||||
set curlEasyHandle2 [curl::init]
|
||||
|
||||
$curlEasyHandle1 configure -url http://127.0.0.1/~andres/ -file index.html
|
||||
$curlEasyHandle2 configure -url http://127.0.0.1/ -file index2.html
|
||||
|
||||
puts "Creating the multi handle"
|
||||
|
||||
set curlMultiHandle [curl::multiinit]
|
||||
|
||||
puts "Adding easy handles to the multi one"
|
||||
|
||||
$curlMultiHandle addhandle $curlEasyHandle1
|
||||
$curlMultiHandle addhandle $curlEasyHandle2
|
||||
|
||||
puts "We start the transfer"
|
||||
|
||||
StartTransfer $curlMultiHandle
|
||||
|
||||
puts "Transfer done, cleanning up"
|
||||
|
||||
$curlMultiHandle removehandle $curlEasyHandle1
|
||||
$curlMultiHandle removehandle $curlEasyHandle2
|
||||
|
||||
$curlMultiHandle cleanup
|
||||
$curlEasyHandle1 cleanup
|
||||
$curlEasyHandle2 cleanup
|
||||
|
||||
|
52
tests/multi/single.tcl
Executable file
52
tests/multi/single.tcl
Executable file
@ -0,0 +1,52 @@
|
||||
package require TclCurl
|
||||
|
||||
proc Perform {multiHandle} {
|
||||
if {[catch {$multiHandle active} activeTransfers]} {
|
||||
puts "Error checking active transfers: $activeTransfers"
|
||||
return -1
|
||||
}
|
||||
|
||||
if {[catch {$multiHandle perform} running]} {
|
||||
puts "Error: $running"
|
||||
return 1
|
||||
}
|
||||
return $running
|
||||
}
|
||||
|
||||
proc StartTransfer {multiHandle} {
|
||||
while {1==1} {
|
||||
set runningTransfers [Perform $multiHandle]
|
||||
if {$runningTransfers>0} {
|
||||
after 500
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set curlEasyHandle [curl::init]
|
||||
|
||||
$curlEasyHandle configure -url http://127.0.0.1/ -file index.html
|
||||
|
||||
if {[catch {curl::multiinit} curlMultiHandle]} {
|
||||
puts "Error with multi handle init"
|
||||
}
|
||||
|
||||
puts "The multi handle: $curlMultiHandle"
|
||||
|
||||
puts -nonewline "We add the easy handle: "
|
||||
puts [$curlMultiHandle addhandle $curlEasyHandle]
|
||||
|
||||
StartTransfer $curlMultiHandle
|
||||
|
||||
puts "Calling getinfo [$curlMultiHandle getinfo]"
|
||||
|
||||
puts -nonewline "Removing the easy handle: "
|
||||
puts [$curlMultiHandle removehandle $curlEasyHandle]
|
||||
|
||||
puts -nonewline "Cleanup the multi handle handle: "
|
||||
puts [$curlMultiHandle cleanup]
|
||||
|
||||
$curlEasyHandle cleanup
|
||||
|
||||
|
Reference in New Issue
Block a user