r9p

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

commit e20d530e92407be21a5bfad63fa3491433f947cc
parent c72c151943eb8bb4a2b19f402fa127376981d8a0
Author: Kris Maglione <jg@suckless.org>
Date:   Wed, 21 Mar 2007 11:46:06 -0400

Some general cleanup.

Diffstat:
r9p.rb | 4+---
r9p/client.rb | 45++++++++++++++++++++++++++-------------------
r9p/fcall.rb | 6++++++
r9p/serial.rb | 3+--
4 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/r9p.rb b/r9p.rb @@ -1,9 +1,7 @@ $debug ||= 0 module R9P - NoFid = ~0 - NoTag = ~0 - P9Version = '9P2000' + Version = '9P2000' end require 'r9p/thread.rb' diff --git a/r9p/client.rb b/r9p/client.rb @@ -4,9 +4,9 @@ module R9P class Exception <Exception end - class ProtocolException <Exception + class ProtocolException <R9P::Exception end - class RPCError <Exception + class RPCError <R9P::Exception end class Client RootFid = 0 @@ -23,7 +23,6 @@ module R9P end include Constants include Qlock - attr_reader :msize def initialize(con, root = nil) qlinit @@ -34,13 +33,13 @@ module R9P fcall = Fcall.from dat } - resp = dorpc Fcall::Tversion, :version => P9Version, :msize => 65535 - if resp.version != P9Version + resp = dorpc Fcall::Tversion, :version => R9P::Version, :msize => 65535 + if resp.version != R9P::Version raise ProtocolException, "Can't speak 9P version '#{resp.version}'" end @msize = resp.msize - dorpc Fcall::Tattach, :fid => RootFid, :afid => NoFid, :uname => ENV['USER'], :aname => '' + dorpc Fcall::Tattach, :fid => RootFid, :afid => Fcall::NoFid, :uname => ENV['USER'], :aname => '' if root path = splitpath(root) @@ -98,14 +97,25 @@ module R9P end private :getfid, :putfid + def clunk(fid) + dorpc Fcall::Tclunk, :fid => fid + ensure + putfid fid + end + private :clunk + def walk(path) + path = path.clone fid = getfid - dorpc Fcall::Twalk, :fid => RootFid, :newfid => fid, :wname => path + ofid = RootFid + begin + dorpc Fcall::Twalk, :fid => ofid, :newfid => fid, :wname => path.slice!(0..Fcall::MaxWelem-1) + ofid = fid + end while path.length > 0 begin yield fid rescue - dorpc Fcall::Tclunk, :fid => fid - putfid fid + clunk fid raise end end @@ -119,7 +129,7 @@ module R9P end file = File.new(self, resp, fid, mode) do - putfid fid + clunk fid end @files[fid] = file @@ -169,7 +179,7 @@ module R9P resp = dorpc Fcall::Tstat, :fid => fid resp.stat ensure - dorpc Fcall::Tclunk, :fid => fid + clunk fid end end rescue RPCError @@ -194,6 +204,11 @@ module R9P @fd = nil end + def dorpc(clas, args = {}) + @client.dorpc clas, args.merge!(:fid => @fid) + end + private :dorpc + def stat resp = dorpc Fcall::Tstat resp.stat @@ -254,9 +269,6 @@ module R9P def close fd_close if @fd ensure - qsync { - dorpc Fcall::Tclunk - } @cleanup.call self @tg = @fid = @client = @qid = nil @@ -342,11 +354,6 @@ module R9P @fd end end - - def dorpc(clas, args = {}) - @client.dorpc clas, args.merge!(:fid => @fid) - end - private :dorpc end end end diff --git a/r9p/fcall.rb b/r9p/fcall.rb @@ -3,6 +3,12 @@ module R9P class Fcall <Serial + module Constants + MaxWelem = 16 + NoTag = ~0 + NoFid = ~0 + end + include Constants Types = [] field :size, :dword, :size, 4 field :type, :byte diff --git a/r9p/serial.rb b/r9p/serial.rb @@ -7,7 +7,6 @@ module R9P :byte => [ 1, 'C' ], :word => [ 2, 'v' ], :dword => [ 4, 'V' ], - :qid => [ 13, 'CVVV' ], } attr_reader :fields, :serial, :opstack @@ -147,7 +146,7 @@ module R9P "fields: #{@fields.inspect}, serial: #{@serial.inspect}, stack: #{@opstack.inspect}" end def inspect - "#<#{self.class.inspect} #{to_s.inspect}>" + "#<#{self.class.inspect} #{to_s}>" end class Field