1# -*- tcl -*- 2# # ## ### ##### ######## ############# 3# (C) 2009 Andreas Kupries 4 5# @@ Meta Begin 6# Package tcl::chan::nullzero 1 7# Meta as::author {Andreas Kupries} 8# Meta as::copyright 2009 9# Meta as::license BSD 10# Meta description Implementation of a channel combining 11# Meta description Memchan's null and zero channels in a 12# Meta description single device. Based on Tcl 8.5's channel 13# Meta description reflection support. Exports a single 14# Meta description command for the creation of new 15# Meta description channels. No arguments. Result is the 16# Meta description handle of the new channel. 17# Meta platform tcl 18# Meta require TclOO 19# Meta require tcl::chan::events 20# Meta require {Tcl 8.5} 21# @@ Meta End 22 23# # ## ### ##### ######## ############# 24 25package require Tcl 8.5 26package require TclOO 27package require tcl::chan::events 28 29# # ## ### ##### ######## ############# 30 31namespace eval ::tcl::chan {} 32 33proc ::tcl::chan::nullzero {} { 34 return [::chan create {read write} [nullzero::implementation new]] 35} 36 37oo::class create ::tcl::chan::nullzero::implementation { 38 superclass ::tcl::chan::events ; # -> initialize, finalize, watch 39 40 method initialize {args} { 41 my allow read write 42 next {*}$args 43 } 44 45 # Ignore the data in most particulars. We do count it so that we 46 # can tell the caller that everything was written. Null device. 47 48 method write {c data} { 49 return [string length $data] 50 } 51 52 # Generate and return a block of N null bytes, as requested. Zero 53 # device. 54 55 method read {c n} { 56 return [binary format @$n] 57 } 58} 59 60# # ## ### ##### ######## ############# 61package provide tcl::chan::nullzero 1 62return 63