read one byte: fconfigure -buffersize 1
Closed / Out of Date558932ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 10 years ago
Descriptionplain2002-05-22 00:14:20
Allow read(n) to read one byte, i.e. a system call of read(2) asks for one byte. At the moment fconfigure(n) accepts a -buffersize argument but it has a minimum size of 10, perhaps this minimun could be 1 instead. It seems really bad not being able to do a read(fd, buf, 1) in tcl. If you do a "read $chan 1" a system call read is performed with the "buffersize" specified in fconfigure or some default (4k on Linux). So, if you do fconfigure $chan -buffersize 10 read $chan 1 a read(fd, buf, 10) system call is issued. So far, so good. However, you cannot specify a -buffersize of less than 10. Actually, fconfigure accepts it but no reads are ever issued. regards, john
hobbsplain2002-05-22 09:03:14
Logged In: YES user_id=72656 I don't see why we need a minimum buffersize (well, at least 1 I guess).
dkfplain2002-05-22 20:03:12
Logged In: YES user_id=79902 read(2) isn't required to completely fill the buffer it is passed. Check the return code to the syscall to see how much was actually read in... This only matters when Tcl and some other software not sharing Tcl's I/O layer are competing for a channel that is producing more than each piece of software wants to read at a time. I think...
dgpplain2002-05-22 22:02:46
Logged In: YES user_id=80530 Note there's a documented max limit on -buffersize of one million as well. What is the origin/purpose of these limits? How were these values chosen?
nobodyplain2002-05-23 07:14:22
Logged In: NO I understand read(2)'s behaviour is dependent on the type of file descriptor you are reading (file, pipe, etc.) and, for that matter, the OS, too. However, there are situtations where a real read(2) of one byte is required and, anyway, it's pretty odd not being able to do it. > I have to admit it was/is my belief too that [read] with an explicit > size allocates a buffer with that size and reads it in as less > iterations as possible. Seems that I have to recheck this. Try this while running strace on tclsh: set c [open /dev/zero] fconfigure $c -buffersize 10 -buffering none read $c 1 and you will see a read(fd, buf, 10) being issued. Now do the same with: set c [open /dev/zero] fconfigure $c -buffersize 1 -buffering none read $c 1 and no read(2) gets executed at all! Now that's kind of ok because it explicitly says the smallest buffersize is 10. I believe there should be no bounds on buffersize. I could accept begrudgingly an upper limit but a random lower limit of 10 is really wierd. regards, john
dgpplain2016-08-24 12:15:49
This was fixed in 2005.
Log in (anonymous is fine) to add a comment.