Code: Select all
proc get:rss { url port get offset } {
if { [catch {set sock [socket -async $url $port]}] } {
putlog "error: Can't reach $url $port"
return 0
} else {
...
Code: Select all
proc get:rss { url port get offset } {
if { [catch {set sock [socket -async $url $port]}] } {
putlog "error: Can't reach $url $port"
return 0
} else {
...
Code: Select all
proc get:rss2 { url port get offst news } {
set ::sid [socket $url $port]
fconfigure $::sid -buffering line -blocking 0
fileevent $::sid readable gotdata:rss
}
proc gotdata:rss { } {
...
}
-async
The -async option will cause the client socket to be connected asynchronously. This means that the socket will be created immediately but may not yet be connected to the server, when the call to socket returns. When a gets or flush is done on the socket before the connection attempt succeeds or fails, if the socket is in blocking mode, the operation will wait until the connection is completed or fails. If the socket is in nonblocking mode and a gets or flush is done on the socket before the connection attempt succeeds or fails, the operation returns immediately and fblocked on the socket returns 1.
Code: Select all
set utimer [utimer 10 [list close:socket [set sock [socket -async $url 80]]]]
Code: Select all
proc test:rss { url port get offset } {
global noff
set ::sid [socket $url $port]
set noff($::sid) 1
fconfigure $::sid -buffering line -blocking 0
fileevent $::sid readable "gotdata $::sid $offset"
puts $::sid "GET $get HTTP/1.0"
puts $::sid "User-Agent: bot by ex"
puts $::sid "Host: $url"
puts $::sid "Connection: close"
puts $::sid ""
flush $::sid
}
proc gotdata { sid offset } {
global noff geturl
if {[gets $sid bl] > 0} {
putlog "$bl $noff($sid)"
if {[regexp {^.*<title>(.+?)</title>.*} $bl num title]} {
if {$noff($sid) < $offset} {
incr noff($sid)
} else {
set geturl($sid) $title
}
} elseif { [regexp ^.*link>(.+?)</link.* $bl num link] && [info exists geturl($sid)] } {
set title [ns:clean:news $geturl($sid)]
putlog "\002$title\002 \xbb\xbb $link"
unset noff($sid)
unset geturl($sid)
close $sid
}
}
}
Code: Select all
dnslookup www.google.de getgoogledns:cb
dnslookup www.filemirrors.com getfmdns:cb
proc getgoogledns:cb {ip host status} { set ::googleip $ip }
proc getfmdns:cb {ip host status} { set ::fmip $ip }