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

Also available in: Atom PDF

Like0
Like0Like0Like0