I/O Subsystem: Add API Tcl_OutputBuffered(chan)Rolf Schroedter$Revision: 1.4 $
This document proposes the new public function Tcl_OutputBuffered(), analogous to the existing public function Tcl_InputBuffered().
Tcl has a Tcl_InputBuffered() function but no analog function for the output buffer. A Tcl_OutputBuffered() function would be useful for non-blocking channel drivers which need to know the number of bytes pending in Tcl's output queue.
The implementation of allows one to query the number of bytes in the channels input and output queues with a [fconfigure -queue] option. This is a useful feature especially for serial ports because the input/output may be really slow or even stall.
On the driver level only the number of bytes in the system queue can be queried. For a non-blocking channel there may also be some pending output in Tcl buffers. Obviously there is not much sense to know only the byte counter at driver level without knowing Tcl_OutputBuffered().
It could also be useful to add general [fconfigure -inputbuffer -outputbuffer] options for all channels returning the values from Tcl_InputBuffered(chan) and Tcl_OutputBuffered(chan) respectively.
At this opportunity the code of Tcl_Seek() and Tcl_Tell() may be shortened, because it repeats the code of Tcl_InputBuffered() and Tcl_OutputBuffered().
This function would be added to generic/tclIO.c and be stubs enabled. This new API should not have any impact on existing applications.
The implementation is analog to what is done in Tcl_Tell():
Lyo=ICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tICo=ICogVGNsX091dHB1dEJ1ZmZlcmVkIC0tICo=ICoJUmV0dXJucyB0aGUgbnVtYmVyIG9mIGJ5dGVzIG9mIG91dHB1dCBjdXJyZW50bHkgYnVmZmVyZWQgaW4gdGhlICoJY29tbW9uIGludGVybmFsIGJ1ZmZlciBvZiBhIGNoYW5uZWwuICo=ICogUmVzdWx0czo=ICoJVGhlIG51bWJlciBvZiBvdXRwdXQgYnl0ZXMgYnVmZmVyZWQsIG9yIHplcm8gaWYgdGhlIGNoYW5uZWwgaXMgbm90ICoJb3BlbiBmb3Igd3JpdGluZy4=ICo=ICogU2lkZSBlZmZlY3RzOg==ICoJTm9uZS4=ICo=ICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t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