Project

General

Profile

Actions

Bug #3739

closed

IO sets streams attached to pseudo-terminal devices to buffered

Added by easco (Scott Thompson) over 13 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
Backport:
[ruby-core:31835]

Description

=begin
In embedding ruby into an application I opened a pseduo-terminal using the system call "openpty".

I passed the file descriptor for one end of the pseudo terminal to IO::for_fd to create a Ruby IO object.

In the implementation of rb_io_fdopen, the source code allocates a stream (FILE *) for that descriptor and sets the stream to fully buffered using setvbuf.

For a terminal stream, however, I would prefer to have the stream be line buffered (setlinebuf or setvbuf with the constant _IOLBF). Otherwise a large number of lines of text must pass through the buffer before they are passed to the other side of the pseudo terminal connection.

Setting my Ruby IO object to "sync" (i.e. my_io_object.sync = true) does not work. It apparently removes a set of buffers maintained by the Ruby environment in addition to those maintained by the system. Calling "flush" on the IO object also fails to push the text through because, like sync, flush refers to buffers kept by the Ruby runtime and not the system buffers.

The requirement that I call some kind of "flush" or "sync" routine would also be inconvenient for me because I do not necessarily control the code that I am running in the interpreted environment.

The IO object that for_fd is returning does respond properly to the "tty?" and "istty" methods. Perhaps if you create an IO object and istty is true then rb_fdopen should use setvbuf to set the stream to be line buffered.

(NOTE I am NOT forking a subprocess or spawning another ruby process. I am also NOT using the pseudo terminal to replace stdout, stderr, or stdin)

FWIW, I found this issue alluded to in the Ruby Forums a number of years back in regards to the popen3 call:

http://www.ruby-forum.com/topic/152548
=end

Actions #1

Updated by akr (Akira Tanaka) over 13 years ago

=begin
2010/8/24 Scott Thompson :

Bug #3739: IO sets streams attached to pseudo-terminal devices to buffered
http://redmine.ruby-lang.org/issues/show/3739

Author: Scott Thompson
Status: Open, Priority: Normal
Category: core

ruby -v: ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]

In the implementation of rb_io_fdopen, the source code allocates a stream (FILE *) for that descriptor and sets the stream to fully buffered using setvbuf.

Ruby 1.9 doesn't use stdio buffering.

It is recommended to show a small script to reproduce the problem
before describing your investigation.

Tanaka Akira

=end

Actions #2

Updated by shyouhei (Shyouhei Urabe) over 13 years ago

  • Status changed from Open to Feedback

=begin

=end

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Feedback to Rejected

I close this as Rejected since no feedback provided.
Please reopen this if it still happens on the latest version of ruby.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0