Object ::xo::mr::connchan (public)
::xo::MessageRelay ::xo::mr::connchan
Defined in packages/xotcl-core/tcl/message-relay-procs.tcl
Message relay based on ns_connchan
- Testcases:
- No testcase defined.
Source code: :object method cleanup {key handle} { catch {ns_connchan close $handle} catch {nsv_unset mr_connchan_$key $handle} } :public object method subscribe {key {-initmsg ""} {-mode ""} } { #ns_log notice "#### [self] subscribe $key mode $mode" # # Unplug the connection channel from the current connection # thread. The currently unplugged channels can be queried via # "ns_connchan list" # set handle [ns_connchan detach] # # should check and append # if {![nsv_exists mr_connchan_$key $handle]} { nsv_set mr_connchan_$key $handle $mode try { ns_connchan write $handle [:start_of_page $mode] } on error {errorMsg} { ns_log warning "message relay: write on <$key> failed: $errorMsg" :cleanup $key $handle } } else { ns_log warning "message relay: duplicate registration for <$key> attempted" } #::bgdelivery do ::Subscriber new # -channel $ch -key $key # -user_id [ad_conn user_id] -mode $mode } :public object method send_to_subscriber {key msg} { # # Write directly to the subscribers from the connection thread # via ns_connchan. It would be possible, to perform asynchronous # operations via "ns_connchan callback", which would be handled # in the background. Not sure, this is necessary. # #ns_log notice "#### [self] send_to_subscriber <[nsv_array names mr_connchan_$key]>" foreach handle [nsv_array names mr_connchan_$key] { try { set mode [nsv_get mr_connchan_$key $handle] ns_connchan write $handle [:encode_message $mode $msg] } on error {errorMsg} { ns_log warning "message relay: duplicate registration for <$key> attempted" :cleanup $key $handle } } } :public object method can_be_used {} { # # ns_connchan can be used on every recent NaviServer. # return [expr {[info commands ::ns_connchan] ne ""}] } :public object method sweep {key} { # # For the time being, do nothing. Since the chat is verbose on # logins/logouts, write operations will fail, in which case the # array is cleaned up. If this is not sufficient, probably a # "ns_connchan eof" operation would be useful. # }XQL Not present: Generic, PostgreSQL, Oracle