Bi-directional pipe?

B

Brian Candler

Is there any standard Ruby way of creating a bidirectional pipe or
socketpair?

I want to pass a single IO-like object around, but to be able to both read
and write from the other end. (What I'm actually trying to do is to put a
facade around Net::SSH so that the command channel can be passed in as a
proxy to Net::Telnet, but I can think of other uses of this)

IO.popen(..., "w+") does make such a bidirectional pipe, but as far as I can
see only for communicating with a child process.

Any ideas?

Thanks,

Brian.
 
R

Rob Biedenharn

Is there any standard Ruby way of creating a bidirectional pipe or
socketpair?

I want to pass a single IO-like object around, but to be able to
both read
and write from the other end. (What I'm actually trying to do is to
put a
facade around Net::SSH so that the command channel can be passed in
as a
proxy to Net::Telnet, but I can think of other uses of this)

IO.popen(..., "w+") does make such a bidirectional pipe, but as far
as I can
see only for communicating with a child process.

Any ideas?

Thanks,

Brian.

rd, wr = IO.pipe

comes to mind.

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 
B

Brian Candler

rd, wr = IO.pipe

comes to mind.

That's a *unidirectional* pipe. At least, all the rdoc stuff says that one
end is a reader and the other end is a writer.
 
B

Brian Candler

require 'socket'
Socket.pair ....


irb(main):015:0> require 'socket'
=> true
irb(main):016:0> a = Socket.pair
ArgumentError: wrong number of arguments (0 for 3)
from (irb):16:in `pair'
from (irb):16
from :0

OK, so it exists, it's just not documented in ri - time to grep the source I
guess. Thanks for the pointer.
 
A

ara.t.howard

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,998
Messages
2,570,242
Members
46,834
Latest member
vina0631

Latest Threads

Top