lib/rio/stream/duplex.rb in rio-0.4.2 vs lib/rio/stream/duplex.rb in rio-0.5.1

- old
+ new

@@ -1,8 +1,8 @@ #-- -# =============================================================================== -# Copyright (c) 2005,2006,2007,2008 Christopher Kleckner +# =========================================================================== +# Copyright (c) 2005-2012 Christopher Kleckner # All rights reserved # # This file is part of the Rio library for ruby. # # Rio is free software; you can redistribute it and/or modify @@ -16,64 +16,102 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Rio; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# =============================================================================== +# =========================================================================== #++ # -# To create the documentation for Rio run the command -# ruby build_doc.rb -# from the distribution directory. -# -# Suggested Reading -# * RIO::Doc::SYNOPSIS -# * RIO::Doc::INTRO -# * RIO::Doc::HOWTO -# * RIO::Doc::EXAMPLES -# * RIO::Rio -# -require 'rio/stream' -require 'rio/stream/open' +#require 'rio/stream' +#require 'rio/stream/duplex' module RIO module Stream module Duplex module Ops module Output def wclose() - #p "wclose #{self}" + p "wclose #{self}" ioh.close_write return self.close.softreset if ioh.closed? self end end end - class Open < RIO::Stream::Open - def output() super.extend(Ops::Output) end - def inout() super.extend(Ops::Output) end - end end end end -__END__ + + module RIO module Stream module Duplex + module Ops + extend Forwardable + extend RIO::Fwd + def base_state() 'Stream::Duplex::Close' end + #def ior() fibproc.pipe.rd end + #def iow() fibproc.pipe.wr end + def ior() ioh() end + def iow() ioh end + end + class Open < RIO::Stream::Open + fwd :data,:fibproc + include Ops + def output() stream_state('Stream::Duplex::Output') end + def input() stream_state('Stream::Duplex::Input') end + def inout() stream_state('Stream::Duplex::InOut') end + #def fibproc() input.fibproc() end + protected + + def open_(*args) + #p callstr('open_',args.inspect)+" mode='#{mode?}' (#{mode?.class}) ioh=#{self.ioh} open?=#{open?}" + self.ioh = self.rl.open(mode?,*args) unless open? + #p data + self + end + end + class Input < RIO::Stream::Input - include Ops::Input + include Ops + fwd :data,:fibproc end class Output < RIO::Stream::Output - include Ops::Output + include Ops + fwd :data,:fibproc + def base_state() 'Stream::Duplex::Close' end + #include Ops::Output end class InOut < RIO::Stream::InOut - include Ops::Output - include Ops::Input + include Ops + fwd :data,:fibproc + def base_state() 'Stream::Duplex::Close' end + #include Ops::Output + #include Ops::Input + def get() + until self.eof? + raw_rec = self._get_rec + return to_rec_(raw_rec) if @get_selrej.match?(raw_rec,@recno) + end + #loop do + # raw_rec = self._get_rec + # return to_rec_(raw_rec) if @get_selrej.match?(raw_rec,@recno) + # break if self.eof? + #end + self.close if closeoneof? + nil +# (closeoneof? ? self.on_eof_close{ nil } : nil) + end + + end + class Close < RIO::Stream::Close + end + class Reset < RIO::Stream::Reset end end end end