|
2023-04-03
| ||
| 18:16 | • Ticket [3096275fff] Sync fcopy buffers input status still Closed with 7 othe... artifact: a1e8dc4f04 user: pooryorick | |
|
2011-08-19
| ||
| 03:24 | • Closed ticket [3096275fff]. artifact: e93262cdf7 user: ferrieux | |
|
2011-07-19
| ||
| 22:42 | • Ticket [3096275fff]: 4 changes artifact: 7f3a4f23ee user: ferrieux | |
|
2010-12-13
| ||
| 20:30 | • Ticket [3096275fff]: 1 change artifact: 61bfd25895 user: ferrieux | |
|
2010-11-05
| ||
| 04:45 | • Ticket [3096275fff]: 4 changes artifact: 4a6d215335 user: ferrieux | |
|
2010-11-04
| ||
| 20:47 | • Ticket [3096275fff]: 2 changes artifact: e83ddea40c user: dgp | |
|
2010-10-28
| ||
| 03:40 | • Ticket [3096275fff]: 4 changes artifact: 02bdaa0ec6 user: ferrieux | |
| 02:33 | • Ticket [3096275fff]: 1 change artifact: 4c95a9252d user: andreas_kupries | |
| 02:33 | • Ticket [3096275fff]: 4 changes artifact: bf2f24cee0 user: andreas_kupries | |
|
2010-10-27
| ||
| 17:13 | • Ticket [3096275fff]: 4 changes artifact: 2b2cba19fb user: ferrieux | |
| 17:13 | • Add attachment fcopysync.patch to ticket [3096275fff] artifact: e92b8d0dba user: ferrieux | |
| 17:12 | • Ticket [3096275fff] Sync fcopy buffers input status still Open with 1 other ... artifact: 4c8306ce41 user: ferrieux | |
| 17:12 | • Ticket [3096275fff]: 4 changes artifact: a6d871f212 user: ferrieux | |
| 08:32 | • New ticket [3096275fff]. artifact: 2359aa3691 user: ferrieux | |
Sync fcopy buffers input
Closed / Fixed3096275fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 4 years ago
Descriptionplain2010-10-27 08:32:25
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 :/
ferrieuxplain2010-10-27 17:12:32
Attached tiny patch fixes the issue, by adding an allowShortReads flag to DoRead, for use only inside CopyData when the input channel is blocking. This allows to exploit the "half-blocking" semantics of pipes and sockets, which can do short reads in blocking mode, thus keeping the overall spirit of sync fcopy (ie don't use the event loop). Checked against the test suite. Again, this removes a day-1, but undocumented, limitation. Raising prio to ask for permission to commit.
ferrieux Ticket [3096275fff]: 1 change
[History diff]2010-10-27 17:12:33
ferrieuxplain2010-10-27 17:13:16
File Added - 391352: fcopysync.patch
andreas_kupriesplain2010-10-28 02:33:32
I can't see anything bad with this, except, maybe, that the sync fcopy go into a tight loop consuming lots of cpu because of a continuous series of 0-char reads until something is typed in. Would like to get a second opinion, assigning to Jeff.
andreas_kupries Ticket [3096275fff]: 1 change
[History diff]2010-10-28 02:33:33
ferrieuxplain2010-10-28 03:40:32
That can no more occur than before: the new behavior, allowShortReads, is only ever activated when
!GotFlag(inStatePtr, CHANNEL_NONBLOCKING)
that is, only for a blocking channel, ie in sync fcopy.
If you know of another situation yielding a busyloop, please elaborate.
dgp Ticket [3096275fff]: 2 changes
[History diff]2010-11-04 20:47:51
ferrieuxplain2010-11-05 04:45:05
Also ran tclbench: no slowdown.
ferrieux Ticket [3096275fff]: 1 change
[History diff]2010-12-13 20:30:44
ferrieuxplain2011-07-19 22:42:07
Any hope to review for 8.6.0 ?
ferrieuxplain2011-08-19 03:24:24
Committed.
pooryorickwiki2023-04-03 18:16:19
This report dealt with ReadBytes(). See also [9ca87e6286] for the same issue with ReadChars().
Log in (anonymous is fine) to add a comment.
Attachments:
- fcopysync.patch [download] added by ferrieux on 2010-10-27 17:13:15. [details]