/usr/share/tcltk/xotcl1.6.7-comm/Connection.xotcl is in xotcl 1.6.7-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | # -*- tcl -*- $Id: Connection.xotcl,v 1.6 2006/09/27 08:12:40 neumann Exp $
package provide xotcl::comm::connection 1.0
package require XOTcl
namespace eval ::xotcl::comm::connection {
namespace import ::xotcl::*
Class Connection -parameter {host port req socket handle}
Connection proc make {r host port reuse reusedVar} {
#my showCall
my instvar openConnections
upvar [self callinglevel] $reusedVar reused
if {$reuse} {
set handle $host:$port-[$r set blocking]
#if {[array exists openConnections]} {parray openConnections}
if {![info exists openConnections($handle)]} {
# there is no persistent connection, we create a new one
set reused 0
set openConnections($handle) \
[Connection new -host $host -port $port -req $r -handle $handle]
#my showMsg "$openConnections($handle) CONNECTION add for $handle added"
} else {
# there is a persistent connection
set reused 1
set c $openConnections($handle)
$c instvar req
#::puts stderr "$c CONNECTION reuse for $handle ($c) new req=$r"
if {[info exists req]} {
# the persistent connection is active with some request $req
#::puts stderr "$c CONNECTION req $req already active"
} else {
# the persistent connection is currently not active
$c set req $r
}
}
return $openConnections($handle)
} else {
set reused 0
return [Connection new -host $host -port $port -req $r]
}
}
Connection proc removeHandle handle {
#my showVars
#puts stderr "***************** unsetting $handle ***************"
if {[my exists openConnections($handle)]} {
my unset openConnections($handle)
}
}
Connection instproc init args { ;# the constructor creates the socket
my set blocked {}
next
if {[my exists socket]} {
my set keepOpen 1
} else {
my set keepOpen 0
if {[catch {my socket [socket -async [my host] [my port]]} msg]} {
my set error $msg
return
}
}
::fconfigure [my socket] -blocking false -buffersize 16384
}
#Connection instproc STATUS {ctx} {
# my instvar socket
# ::puts stderr "*** $ctx: $socket blocking=[::fconfigure $socket -blocking]"
#}
Connection instproc destroy {} { ;# the destructor closes the socket
#my showCall
if {[my exists handle]} {
#my showVars handle
# the connection was created via make
[self class] removeHandle [my handle]
#::puts stderr "my CONNECTION close and destroy [my handle]"
} else {
#::puts stderr "my CONNECTION close and destroy"
}
# in cases of errors we might not have a socket yet
if {[my exists socket]} {
close [my socket]
}
next
}
Connection instproc translation {translation} {
#showCall
::fconfigure [my socket] -translation $translation
}
Connection instproc importSSL args {
#my showCall
package require tls
eval tls::import [my socket] $args
}
Connection instproc fconfigure args {
#my showCall
eval ::fconfigure [my socket] $args
}
Connection instproc event {type r method} {
#my showCall
my instvar req blocked
# is the request in the argument list the currently active request?
if {[info exists req] && $r == $req} {
# a request can overwrite its active request
if {$method eq ""} {
::fileevent [my socket] $type ""
#my showMsg "CONNECTION clear for [my socket]"
} else {
#my showMsg "CONNECTION register for [my socket]"
::fileevent [my socket] $type [list $r $method]
}
} else {
#my showMsg "event BLOCKING current request=$req, new=$r $method"
#my showMsg "event BLOCKING rd=[::fileevent [my socket] readable]"
#my showMsg "event BLOCKING wr=[::fileevent [my socket] writable]"
#my showMsg "event BLOCKING bl=$blocked"
::lappend blocked $r $type $method
}
}
Connection instproc hold {} {
my set continueCmd [list ::fileevent [my socket] readable \
[::fileevent [my socket] readable]]
::fileevent $socket readable {}
#my showVars continueCmd
}
Connection instproc resume {} {
#my showCall
if {[my exists continueCmd]} {
eval [my set continueCmd]
my unset continueCmd
}
}
Connection instproc puts {string} {
#my showCall
if {[catch {::puts [my socket] $string} msg]} {
::puts stderr message=$msg
}
}
Connection instproc puts-nonewline {string} {
#my showCall
if {[catch {::puts -nonewline [my socket] $string} msg]} {
::puts stderr message=$msg
}
}
Connection instproc gets {var} {
#my showCall
upvar [self callinglevel] $var result
if {[catch {set n [::gets [my socket] result]} msg]} {
my set error $msg
#my showMsg "CONNECTION error"
return 0
}
#my showMsg "n=$n, result=<$result>"
return $n
}
Connection instproc read {} {
#my showCall
my instvar socket
if {[catch {set result [::read $socket [::fconfigure $socket -buffersize]]} msg]} {
my set error $msg
return ""
}
#my showMsg Done
return $result
}
Connection instproc readSize {length} {
if {[catch {set result [::read [my socket] $length]} msg]} {
my set error $msg
return 0
}
return $result
}
Connection instproc flush {} {
#my showCall
if {[catch {::flush [my socket]} msg]} {
my set error $msg
}
}
Connection instproc eof {} {
#my showCall
if {[my exists error]} {
return 1
} else {
return [::eof [my socket]]
}
}
Connection instproc close {} {
#my showCall
my instvar req socket blocked
if {![info exists socket]} return ;# error during connection open
::fileevent $socket readable ""
::fileevent $socket writable ""
$req freeConnection
if {[my exists persistent]} {
my flush
#::puts stderr "[self] PERSISTENT CONNECTION wanna close"
if {$blocked eq ""} {
::fileevent $socket readable [list [self] destroy]
unset req
} else {
#my showVars blocked
set req [lindex $blocked 0]
set type [lindex $blocked 1]
set method [lindex $blocked 2]
set blocked [lrange $blocked 3 end]
#my showMsg "in persistent connection unblock $type [list $req $method]"
::fileevent $socket $type [list $req $method]
}
} else {
#my showMsg "in nonpersistent connection blocked=$blocked"
if {$blocked ne ""} {
set req [lindex $blocked 0]
set type [lindex $blocked 1]
set method [lindex $blocked 2]
set nblocked [lrange $blocked 3 end]
close $socket
unset socket
if {[my exists handle]} {
[self class] removeHandle [my handle]
}
if {[my exists error]} {
#my showMsg "UNSETTING ERROR -----------"
my unset error
}
my init
set blocked $nblocked
::fileevent $socket $type [list $req $method]
#my showMsg "REANIMATE $socket $type [list $req $method]"
#my showVars
} else {
#my showMsg "Nothing blocked: readable=[::fileevent $socket readable]"
my destroy
}
}
}
Connection instproc makePersistent {p} {
if {$p} {
my set persistent 1
} else {
if {[my exists persistent]} {
my unset persistent
#my showMsg "no longer persistent"
}
}
}
namespace export Connection
}
namespace import ::xotcl::comm::connection::*
if {[info command bgerror] eq ""} {
proc bgerror {msg} { puts stderr "******* bgerror $msg $::errorInfo*****"}
}
|