Skip to content
Tcl Source Code View Ticket
Login

View Ticket

read all-or-nothing option

Open787960ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 21 years ago
Descriptionplain2003-08-13 10:45:00
Since tcl's underlying I/O system seems to support this
already, it would be handy if read had an
"all-or-nothing" option which, when used with a channel
in non-blocking mode, causes read to return data only
when the specified number of bytes are available for
reading. If insufficient data is available, it returns
nothing. This is in contrast to the normal mode of
operation in which the available characters are
returned even if less than the number requested.
Suggestion submitted by Mario Becroft <[email protected]>
dkfplain2003-10-29 16:19:37
Logged In: YES 
user_id=79902

I like this idea; perhaps it would be best done as an option
to [read]?  It might also be nice to have an option to get
data in a certain granularity, so that you can guarantee
(for example) that you only ever get complete 8-byte
integers suitable for feeding into [binary scan].  Sure you
can work around this sort of thing, but it is a pain and can
easily be done in Tcl's channel layer since you've already
got something like that for handling encodings and the
reading of lines...

It's a good and simplifying suggestion, so boosting the Prio
andreas_kupriesplain2006-03-17 06:05:59
Logged In: YES 
user_id=75003

While I like the idea of [read -xxx 8] for xxx the name of
the option, I am not sure that I understand the need for an
additional option -yyy for the granularity. I want the
8-byte integer, I say [read -xxx 8] ... Ah. Wait. you might
wish to read an array of 8-byte integer, eh ? Say, 10 of them.

And instead of writing [read -xxx 80], or even [read -xxx
[expr {10*8}]] (well, with appropriate variables, you (dkf)
are thinking about [read -xxx -yyy 8 10]. And the default
for -yyy is 1, i.e. bytes.

In this context [read -all-or-nothing -size 8 10].

Ok.
Log in (anonymous is fine) to add a comment.