r9p

git clone git://oldgit.suckless.org/r9p/
Log | Files | Refs

commit 5fdc53adedcdf8da085f6c9c683f77a198bf2911
parent b122f0a35779899572a459d53d75e2d6a9e2327a
Author: Kris Maglione <jg@suckless.org>
Date:   Wed, 14 Mar 2007 20:13:15 -0400

Improved r9p/test.rb. Fixed some bugs.

Diffstat:
r9p/client.rb | 25+++++++++++++++++++------
r9p/serial.rb | 2+-
r9p/test.rb | 66+++++++++++++-----------------------------------------------------
3 files changed, 33 insertions(+), 60 deletions(-)

diff --git a/r9p/client.rb b/r9p/client.rb @@ -34,7 +34,7 @@ module R9P resp = dorpc Fcall::Tversion, :version => P9Version, :msize => 65535 if resp.version != P9Version - throw ProtocolException, "Can't speak 9P version '#{resp.version}'" + throw ProtocolException.new("Can't speak 9P version '#{resp.version}'") end @msize = resp.msize @@ -63,16 +63,17 @@ module R9P } ensure @mux.fd.close + @mux = nil end def dorpc(clas, *args) fcall = clas.new *args resp = @mux.rpc fcall if resp.kind_of? Fcall::Rerror - throw Exception, "RPC returned error: #{fcall.class.inspect} #{fcall.fields.inspect}: #{resp.ename}" + throw Exception.new("RPC returned error: #{fcall.class.inspect} #{fcall.fields.inspect}: #{resp.ename}") end if fcall.type != resp.type ^ 1 - throw ProtocolException, "Missmatched RPC message types: #{fcall.class.inspect} => #{resp.class.inspect}" + throw ProtocolException.new("Missmatched RPC message types: #{fcall.class.inspect} => #{resp.class.inspect}") end resp end @@ -87,7 +88,7 @@ module R9P if @files.delete(fid) @fids.push fid else - throw Exception, "Attempt to free unused fid" + throw Exception.new("Attempt to free unused fid") end } end @@ -173,6 +174,17 @@ module R9P } off end + def readdir + unless @qid.type.to_i&Qid::QTDIR + raise Exception.new("Can only call readdir on a directory") + end + data = '' + begin + dat = read(@iounit, data.length) + data << dat if dat + end while dat + Stat.from_data data + end def close fd_close if @fd @@ -182,11 +194,12 @@ module R9P } @client.putfid @fid - @tg = @fd = @fid = @client = @qid = nil + @tg = @fid = @client = @qid = nil end def fd_close @fd.close ensure + @fd = nil @tg.list.each { |thr| thr.kill if thr.alive? thr.join @@ -195,7 +208,7 @@ module R9P def to_fd if @fd - throw Exception, "File descriptor already open for file" + throw Exception.new("File descriptor already open for file") end fds = Socket::pair Socket::PF_UNIX, Socket::SOCK_STREAM, 0 diff --git a/r9p/serial.rb b/r9p/serial.rb @@ -147,7 +147,7 @@ module R9P "fields: #{@fields.inspect}, serial: #{@serial.inspect}, stack: #{@opstack.inspect}" end def inspect - "#<#{self.class.inspect} #{to_s}>" + "#<#{self.class.inspect} #{to_s.inspect}>" end class Field diff --git a/r9p/test.rb b/r9p/test.rb @@ -4,62 +4,22 @@ module R9P include Client::Constants Client.new('unix!/tmp/ns.kris.:1/wmii') { |c| - c.open("event", OWRITE) { |f| - f.to_fd { |fd| - fd.print "Foo!\n" + c.open('/') { |f| + f.readdir.each { |f| + puts "/#{f.name}:" + f.fields.each_pair { |k, v| + puts "\t#{k.id2name}: #{v.inspect}" + } } } - c.open("keys") { |f| + c.open('/keys') { |f| + puts "\n/keys:" print f.read } + c.open('/ctl', OREAD) { |f| + f.to_fd { |fd| + print "From /ctl: #{fd.readline}" + } + } } end - -=begin - -include Client::Constants - -$pipe = UNIXSocket.new "/tmp/ns.kris.:1/wmii" -#$pipe = IO.for_fd(0, "r+") - -def dorpc(fcall) - p fcall - fcall.serialize - $pipe.write(fcall.serial) - - data = $pipe.read(4) - size, = data.unpack("V") - data << $pipe.read(size-data.length) - - fcall = Fcall.from(data) - p fcall - print "\n\n" - fcall -end - -$debug = 0 - -rversion =dorpc Fcall::Tversion.new(:tag => 1, :msize => 8192, :version => "9P2000") -dorpc Fcall::Tattach.new(:tag => 1, :fid => 1, :afid => ~0, :uname => "kris", :aname => "kris") -dorpc Fcall::Twalk.new(:tag => 1, :fid => 1, :newfid => 3, :wname => [ "ctl" ]) -dorpc Fcall::Tstat.new(:tag => 1, :fid => 3, :offset => 0, :count => 500) -dorpc Fcall::Topen.new(:tag => 1, :fid => 3, :mode => OREAD) - -off = 0 -begin - fcall = dorpc Fcall::Tread.new(:tag => 1, :fid => 3, :offset => off, :count => rversion.msize) - print fcall.data - off += fcall.data.length -end while fcall.data.length > 0 - -print "Done.\n" - -exit - -fcall = dorpc Fcall::Tread.new(:tag => 1, :fid => 3, :offset => 0, :count => 500) -print "Stats: " -Stat.from_data(fcall.data).each do |i| - i.fields.each_pair { |i, j| print "#{i} => #{j}\n" } - print "\n" -end -=end