Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: a1e8dc4f04ebc8aa9998a94572cfff734d3d8fba4b96c58d4102d161fa2a64ca
Ticket: 3096275fffffffffffffffffffffffffffffffff
Sync fcopy buffers input
User & Date: pooryorick on 2023-04-03 18:16:19
Changes

  1. closedate changed to: "2460038.26133465"
  2. closer changed to: "pooryorick"
  3. comment changed to:
    The following script:
    
     fconfigure stdin -translation binary -blocking 0
     fconfigure stdout -buffering none -translation binary
     fcopy stdin stdout
    
    when fed by typing lines to stdin, will not output anything until either 4k have been typed or eof, despite the nonblocking mode on stdin.
    The same using an async fcopy, will work in a more responsive manner:
    
     fcopy stdin stdout -command done
     vwait forever
    
    This is a consequence of the following credo, in a comment in TclCopyChannel:
    
        /*
         * Set up the blocking mode appropriately. Background copies need
         * non-blocking channels. Foreground copies need blocking channels. If
         * there is an error, restore the old blocking mode.
         */
    
    As a consequence, while GetInput happily returns short reads, DoRead insists on filling up its 4k buffer.
    
    That is, sync fcopy will never pass short reads on to the output channel. Hence, sync fcopy is not adapted to live streams, while async fcopy is.
    
    This it at least surprising for the developer, since the sync/async fcopy decision is rather based on external considerations like "do I need to interleave it with other IO" or "do I need to keep a GUI responsive". The fact that chosing sync implies buffering by 4k is nowhere in the docs.
    
    Low prio because it's a Day-1 issue :/
    
  4. icomment:
    This report dealt with ReadBytes().  See also [9ca87e6286] for the same issue with ReadChars().
    
  5. login: "pooryorick"
  6. mimetype: "text/x-fossil-wiki"
  7. severity changed to: "Minor"