Skip to content

Commit ef54029

Browse files
committed
examples/tip.tcl: No need for output-on-writable
Now that the I/O subsystem does auto-flush on write we no longer need to manually set up a writable handler.
1 parent d161274 commit ef54029

File tree

1 file changed

+6
-33
lines changed

1 file changed

+6
-33
lines changed

examples/tip.tcl

+6-33
Original file line numberDiff line numberDiff line change
@@ -107,34 +107,6 @@ stdout buffering none
107107

108108
set status ""
109109
set tilde 0
110-
set tosend {}
111-
112-
# To avoid sending too much data and blocking,
113-
# this sends str in chunks of 1000 bytes via writable
114-
proc output-on-writable {fh str} {
115-
# Add it to the buffer to send
116-
append ::tosend($fh) $str
117-
118-
if {[string length [$fh writable]] == 0} {
119-
# Start the writable event handler
120-
$fh writable [list output-is-writable $fh]
121-
}
122-
}
123-
124-
# This is the writable callback
125-
proc output-is-writable {fh} {
126-
global tosend
127-
set buf $tosend($fh)
128-
if {[string bytelength $buf] >= 1000} {
129-
set tosend($fh) [string byterange $buf 1000 end]
130-
set buf [string byterange $buf 0 999]
131-
} else {
132-
set tosend($fh) {}
133-
# All sent, so cancel the writable event handler
134-
$fh writable {}
135-
}
136-
$fh puts -nonewline $buf
137-
}
138110

139111
proc bgerror {args} {
140112
set status $args
@@ -145,18 +117,19 @@ proc bgerror {args} {
145117

146118
$f readable {
147119
set c [$f read]
120+
#stdout puts "<serial:$c([string bytelength $c]>"
121+
#stdout flush
148122
if {[$f eof]} {
149123
set status "$device: disconnected"
150124
incr done
151-
break
152125
}
153-
output-on-writable stdout $c
126+
stdout puts -nonewline $c
154127
}
155128

156129
proc tilde_timeout {} {
157130
global tilde f
158131
if {$tilde} {
159-
output-on-writable $f ~
132+
$f puts -nonewline ~
160133
set tilde 0
161134
}
162135
}
@@ -177,9 +150,9 @@ stdin readable {
177150
incr done
178151
return
179152
}
180-
output-on-writable $f ~
153+
$f puts -nonewline ~
181154
}
182-
output-on-writable $f $c
155+
$f puts -nonewline $c
183156
}
184157
}
185158

0 commit comments

Comments
 (0)