<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 08:04:45 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='49'>
<header><title>I/O Subsystem: Add API Tcl_OutputBuffered(chan)</title><author address="mailto:rolf.schroedter@dlr.de">Rolf Schroedter</author><status type='project' state='final' tclversion="8.4" vote='after'>$Revision: 1.4 $</status><history></history><created day='25' month='jul' year='2001' /></header>
<abstract>This document proposes the new public function <emph style="italic">Tcl_OutputBuffered()</emph>, analogous to the existing public function <emph style="italic">Tcl_InputBuffered()</emph>.</abstract>
<body><section title="Rationale">
<para>Tcl has a <emph style="italic">Tcl_InputBuffered()</emph> function but no analog function for the output buffer. A <emph style="italic">Tcl_OutputBuffered()</emph> function would be useful for non-blocking channel drivers which need to know the number of bytes pending in Tcl&apos;s output queue.</para>
<para>The implementation of <tipref type="text" tip="35"/> allows one to query the number of bytes in the channels input and output queues with a <emph style="italic">[fconfigure -queue]</emph> option. This is a useful feature especially for serial ports because the input/output may be really slow or even stall.</para>
<para>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 <emph style="italic">Tcl_OutputBuffered()</emph>.</para>
</section>
<section title="Related Ideas">
<para>It could also be useful to add general <emph style="italic">[fconfigure -inputbuffer -outputbuffer]</emph> options for all channels returning the values from <emph style="italic">Tcl_InputBuffered(chan)</emph> and <emph style="italic">Tcl_OutputBuffered(chan)</emph> respectively.</para>
<para>At this opportunity the code of <emph style="italic">Tcl_Seek()</emph> and <emph style="italic">Tcl_Tell()</emph> may be shortened, because it repeats the code of <emph style="italic">Tcl_InputBuffered()</emph> and <emph style="italic">Tcl_OutputBuffered()</emph>.</para>
</section>
<section title="Implementation">
<para>This function would be added to <emph style="italic">generic/tclIO.c</emph> and be stubs enabled. This new API should not have any impact on existing applications.</para>
<para>The implementation is analog to what is done in <emph style="italic">Tcl_Tell()</emph>:</para>
<verbatim><vline encoding='base64'></vline><vline encoding='base64'>Lyo=</vline><vline encoding='base64'>ICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICogVGNsX091dHB1dEJ1ZmZlcmVkIC0t</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICoJUmV0dXJucyB0aGUgbnVtYmVyIG9mIGJ5dGVzIG9mIG91dHB1dCBjdXJyZW50bHkgYnVmZmVyZWQgaW4gdGhl</vline><vline encoding='base64'>ICoJY29tbW9uIGludGVybmFsIGJ1ZmZlciBvZiBhIGNoYW5uZWwu</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICogUmVzdWx0czo=</vline><vline encoding='base64'>ICoJVGhlIG51bWJlciBvZiBvdXRwdXQgYnl0ZXMgYnVmZmVyZWQsIG9yIHplcm8gaWYgdGhlIGNoYW5uZWwgaXMgbm90</vline><vline encoding='base64'>ICoJb3BlbiBmb3Igd3JpdGluZy4=</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICogU2lkZSBlZmZlY3RzOg==</vline><vline encoding='base64'>ICoJTm9uZS4=</vline><vline encoding='base64'>ICo=</vline><vline encoding='base64'>ICotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t</vline><vline encoding='base64'>ICov</vline><vline encoding='base64'></vline><vline encoding='base64'>aW50</vline><vline encoding='base64'>VGNsX091dHB1dEJ1ZmZlcmVkKGNoYW4p</vline><vline encoding='base64'>ICAgIFRjbF9DaGFubmVsIGNoYW47CQkJLyogVGhlIGNoYW5uZWwgdG8gcXVlcnkuICov</vline><vline encoding='base64'>ew==</vline><vline encoding='base64'>ICAgIENoYW5uZWxTdGF0ZSAqc3RhdGVQdHIgPSAoKENoYW5uZWwgKikgY2hhbiktPnN0YXRlOw==</vline><vline encoding='base64'>CQkJCQkvKiBTdGF0ZSBvZiByZWFsIGNoYW5uZWwgc3RydWN0dXJlLiAqLw==</vline><vline encoding='base64'>ICAgIENoYW5uZWxCdWZmZXIgKmJ1ZlB0cjs=</vline><vline encoding='base64'>ICAgIGludCBieXRlc0J1ZmZlcmVkOw==</vline><vline encoding='base64'></vline><vline encoding='base64'>ICAgIGZvciAoYnl0ZXNCdWZmZXJlZCA9IDAsIGJ1ZlB0ciA9IHN0YXRlUHRyLT5vdXRRdWV1ZUhlYWQ7</vline><vline encoding='base64'>CWJ1ZlB0ciAhPSAoQ2hhbm5lbEJ1ZmZlciAqKSBOVUxMOw==</vline><vline encoding='base64'>CWJ1ZlB0ciA9IGJ1ZlB0ci0+bmV4dFB0cikgew==</vline><vline encoding='base64'>CWJ5dGVzQnVmZmVyZWQgKz0gKGJ1ZlB0ci0+bmV4dEFkZGVkIC0gYnVmUHRyLT5uZXh0UmVtb3ZlZCk7</vline><vline encoding='base64'>ICAgIH0=</vline><vline encoding='base64'>ICAgIGlmICgoc3RhdGVQdHItPmN1ck91dFB0ciAhPSAoQ2hhbm5lbEJ1ZmZlciAqKSBOVUxMKSAmJg==</vline><vline encoding='base64'>CSAgICAoc3RhdGVQdHItPmN1ck91dFB0ci0+bmV4dEFkZGVkID4gc3RhdGVQdHItPmN1ck91dFB0ci0+bmV4dFJlbW92ZWQpKSB7</vline><vline encoding='base64'>ICAgICAgICBzdGF0ZVB0ci0+ZmxhZ3MgfD0gQlVGRkVSX1JFQURZOw==</vline><vline encoding='base64'>ICAgICAgICBieXRlc0J1ZmZlcmVkICs9</vline><vline encoding='base64'>ICAgICAgICAgICAgKHN0YXRlUHRyLT5jdXJPdXRQdHItPm5leHRBZGRlZCAtIHN0YXRlUHRyLT5jdXJPdXRQdHItPm5leHRSZW1vdmVkKTs=</vline><vline encoding='base64'>ICAgIH0=</vline><vline encoding='base64'>ICAgIHJldHVybiBieXRlc0J1ZmZlcmVkOw==</vline><vline encoding='base64'>fQ==</vline><vline encoding='base64'></vline></verbatim>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

