chan pending not updated without a gets
Closed1749581fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 19 years ago
Descriptionplain2007-07-07 12:39:41
When a socket is configured non-blocking, chan pending is not updated if [gets] is not called.
For example the following script, will:
1) Always puts 0 to stdout
2) Fire the event handler very rapidly.
# -----
socket -server test 80
proc test {sock args} {
fileevent $sock readable [list pending $sock]
fconfigure $sock -blocking 0
}
proc pending {sock} {
puts [chan pending input $sock]
}
vwait forever
# -----
If a [gets $sock] is added in the pending proc, the chan pending result will be correct and the readable event will not continue to fire.
This will limit the usefulness of chan pending in cases where the read data is not line based (and thus gets is not a good fit)
Furthermore, the behaviour is not consistent with the manual page which states:
returns the number of bytes of input or output (respectively) currently buffered internally for channelId
Nowhere does it state that chan pending will only be updated after a unsuccesful input operation (which can only be achieved by [gets], because read always returns some data (in the unblocking case)).
Additional info:
> tclsh
% parray tcl_platform
tcl_platform(byteOrder) = littleEndian
tcl_platform(machine) = intel
tcl_platform(os) = Windows NT
tcl_platform(osVersion) = 5.1
tcl_platform(platform) = windows
tcl_platform(pointerSize) = 4
tcl_platform(user) = mjanssen
tcl_platform(wordSize) = 4
% info patch
8.5a7
mpc_janssenplain2007-08-15 06:50:06
Logged In: YES user_id=1463011 Originator: YES The behaviour as observed is correct, because chan pending only is useful after an input command. I was really barking up against the wrong tree here. The real issue was that read and gets behave fundamentally different in non-blocking mode. Gets will only return a full line. read will return whatever it has regardless of what you asked for. If read's behaviour would be made the same as gets, chan pending and fblocked would make sense for read also and lessen the bookkeeping burden on the programmer as well.
Log in (anonymous is fine) to add a comment.