32 |
namespace eval ::tcldrop::conn { |
namespace eval ::tcldrop::conn { |
33 |
variable version {0.7} |
variable version {0.7} |
34 |
package provide tcldrop::conn $version |
package provide tcldrop::conn $version |
35 |
variable rcsid {$Id} |
variable rcsid {$Id$} |
36 |
variable Defaults |
variable Defaults |
37 |
if {![info exists ::my-ip]} { set ::my-ip {} } |
if {![info exists ::my-ip]} { set ::my-ip {} } |
38 |
set Defaults(global) [list {async} {1} {buffering} {line} {myaddr} ${::my-ip} {blocking} {0} {timeout} {237}] |
set Defaults(global) [list {async} {1} {buffering} {line} {myaddr} ${::my-ip} {blocking} {0} {timeout} {237}] |
130 |
proc ::tcldrop::conn::Read {idx} { |
proc ::tcldrop::conn::Read {idx} { |
131 |
foreach {a d} [::tcldrop::idx::Info $idx] { array set idxinfo $d } |
foreach {a d} [::tcldrop::idx::Info $idx] { array set idxinfo $d } |
132 |
if {![info exists idxinfo(control)]} { return } |
if {![info exists idxinfo(control)]} { return } |
133 |
# For speed, we read in all available lines (This is absolutely necessary when running inside an Eggdrop, because Eggdrop's event loops are 1 second apart.): |
if {[set error [fconfigure $idxinfo(sock) -error]] != {}} { |
134 |
if {![catch { read -nonewline $idxinfo(sock) } lines]} { |
putloglev d * "net: error!(connect) idx $idx (${error})" |
135 |
foreach line [split $lines \n] { |
# Send {} to the control proc and kill the sock/idx. |
136 |
$idxinfo(control) $idx $line |
# Note, A check on valididx (from the control proc) is one way to tell wether or not an EOF has actually been received. |
137 |
# The update is here so that one connection can't be flooded and drown |
catch { killutimer $idxinfo(connecttimer) } |
138 |
# out the other connections and therefore making them less responsive. |
$idxinfo(control) $idx {} |
139 |
# At least that's what I hope it's good for. =) |
killidx $idx |
140 |
update |
} elseif {[eof $idxinfo(sock)]} { |
|
} |
|
|
} else { |
|
141 |
putloglev d * "net: eof!(read) idx $idx" |
putloglev d * "net: eof!(read) idx $idx" |
142 |
# Send {} to the control proc and kill the sock/idx. |
# Send {} to the control proc and kill the sock/idx. |
143 |
# Note, A check on valididx (from the control proc) is one way to tell wether or not an EOF has actually been received. |
# Note, A check on valididx (from the control proc) is one way to tell wether or not an EOF has actually been received. |
144 |
$idxinfo(control) $idx {} |
$idxinfo(control) $idx {} |
145 |
killidx $idx |
killidx $idx |
146 |
|
} else { |
147 |
|
# For speed, we read in all available lines (This is absolutely necessary when running inside an Eggdrop, because Eggdrop's event loops are 1 second apart.): |
148 |
|
while {[gets $idxinfo(sock) line] >= 1} { $idxinfo(control) $idx $line } |
149 |
} |
} |
150 |
} |
} |
151 |
|
|
158 |
|
|
159 |
proc ::tcldrop::conn::ConnectTimeout {idx} { |
proc ::tcldrop::conn::ConnectTimeout {idx} { |
160 |
putloglev d * "net: timeout!(connect) idx $idx" |
putloglev d * "net: timeout!(connect) idx $idx" |
161 |
|
foreach {a d} [::tcldrop::idx::Info $idx] { array set idxinfo $d } |
162 |
|
catch { killutimer $idxinfo(connecttimer) } |
163 |
|
catch { fileevent $idxinfo(sock) writable {} } |
164 |
killidx $idx |
killidx $idx |
165 |
} |
} |