1 # vim: foldmarker=<<<,>>>
10 variable port
7371 rebind
12 variable con_class
"Con"
14 method get_protocols
{}
15 method register_protocol
{name handler
}
25 method newmsg
{conobj tag subcmd id msg
}
26 method closeclient
{conobj
}
31 body tlc
::Server::constructor {args
} { #<<<1
33 register_protocol
default [tlc
::Protocol ::#auto]
38 body tlc
::Server::destructor {} { #<<<1
44 body tlc
::Server::rebind {} { #<<<1
45 if {$afterid != ""} return
46 set afterid
[after idle
[code
$this _rebind
]]
50 body tlc
::Server::_rebind {} { #<<<1
54 set listen
[socket -server [list $con_class #auto \
55 [list -newmsg_cb [code
$this newmsg
] -server $this -close_cb [code
$this closeclient
]]] $port]
57 set listen
[socket -server [list $con_class #auto \
58 [list -newmsg_cb [code
$this newmsg
] -server $this -close_cb [code
$this closeclient
]]] -myaddr $ip $port]
63 body tlc
::Server::newmsg {conobj tag subcmd id msg
} { #<<<1
64 log debug
"invoking handler for $tag, $subcmd, $id, $msg on $conobj"
65 if {[set ecode
[catch {
66 if {![handlers_available
$tag]} {
67 error "No handlers available for $tag"
69 invoke_handlers
$tag $conobj $subcmd $id $msg
71 if {$ecode != 1} return
72 log
error "tlc::Server::newmsg: error processing callbacks for $tag:\n$::errorInfo"
73 $conobj send 0 $id "Internal error"
78 body tlc
::Server::closeclient {conobj
} { #<<<1
79 # TODO: possible (unlikely) namespace collision of "closeclient" with tags
80 invoke_handlers closeclient
$conobj
84 body tlc
::Server::register_protocol {name handler
} { #<<<1
85 set protocols
($name) $handler
89 body tlc
::Server::get_protocols {} { #<<<1
90 return [array get protocols
]