Encapsulates I/O access over a file handle (fid).

NOTE: this class is NOT thread-safe.

Methods
#
C
N
R
W
Attributes
[R] fid
[R] stat
[R] eof
[RW] pos
Class Public methods
new(agent, path_fid, message_size)
# File lib/rumai/ixp/transport.rb, line 196
        def initialize agent, path_fid, message_size
          @agent  = agent
          @fid    = path_fid
          @msize  = message_size
          @stat   = @agent.stat_fid(@fid)
          @closed = false
          rewind
        end
Instance Public methods
<<(content)

Alias for write

close()

Closes this stream.

# File lib/rumai/ixp/transport.rb, line 216
        def close
          unless @closed
            @agent.clunk @fid
            @closed = true
            @eof = true
          end
        end
closed?()

Returns true if this stream is closed.

# File lib/rumai/ixp/transport.rb, line 227
        def closed?
          @closed
        end
read(partial = false)

Reads some data from this stream at the current position.

partial
When false, the entire content of this stream is read and returned.

When true, the maximum amount of content that can fit inside a single 9P2000 message is read and returned.

If this stream corresponds to a directory, then an Array of Stat (one for each file in the directory) will be returned.

# File lib/rumai/ixp/transport.rb, line 244
        def read partial = false
          raise 'cannot read from a closed stream' if @closed

          content = ''
          begin
            req = Tread.new(
              :fid    => @fid,
              :offset => @pos,
              :count  => @msize
            )
            rsp = @agent.talk(req)

            content << rsp.data
            count = rsp.count
            @pos += count
          end until @eof = count.zero? or partial

          # the content of a directory is a sequence
          # of Stat for all files in that directory
          if @stat.directory?
            buffer = StringIO.new(content)
            content = []

            until buffer.eof?
              content << Stat.from_9p(buffer)
            end
          end

          content
        end
rewind()

Rewinds the stream to the beginning.

# File lib/rumai/ixp/transport.rb, line 208
        def rewind
          @pos = 0
          @eof = false
        end
write(content)

Writes the given content at the current position in this stream.

This method is also aliased as <<
# File lib/rumai/ixp/transport.rb, line 278
        def write content
          raise 'closed streams cannot be written to' if @closed
          raise 'directories cannot be written to' if @stat.directory?

          data = content.to_s
          limit = data.length + @pos

          while @pos < limit
            chunk = data[@pos, @msize]

            req = Twrite.new(
              :fid    => @fid,
              :offset => @pos,
              :count  => chunk.length,
              :data   => chunk
            )
            rsp = @agent.talk(req)

            @pos += rsp.count
          end
        end