def _rpc(self, type, *args): tag = 1 if type == cmd.Tversion: tag = notag if self.verbose: print cmd.repr(type), repr(args) self.sock.send(type, tag, *args) rtype, rtag, vals = self.sock.recv() if self.verbose: print cmd.repr(rtype), repr(vals) if rtag != tag: raise Error("invalid tag received") if rtype == cmd.Rerror: raise P9Error(vals) if rtype != type + 1: raise Error("incorrect reply from server: %r" % [rtype, rtag, vals]) return vals
def rpc(self): """ Process a single RPC message. Return -1 on error. """ type, tag, vals = self.msg.recv() name = "_srv" + cmd.repr(type) if self.verbose: print cmd.repr(type), repr(vals) if hasattr(self, name): func = getattr(self, name) try: rvals = func(type, tag, vals) except ServError, e: self._err(tag, e.args[0]) return 1 # nonfatal if self.verbose: print cmd.repr(type+1), repr(rvals) self.msg.send(type + 1, tag, *rvals)
def _err(self, tag, msg): print 'Error', msg # XXX if self.verbose: print cmd.repr(cmd.Rerror), repr(msg) self.msg.send(cmd.Rerror, tag, msg)
self.msg.send(cmd.Rerror, tag, msg) def rpc(self): """ Process a single RPC message. Return -1 on error. """ type, tag, vals = self.msg.recv() name = "_srv" + cmd.repr(type) if self.verbose: print cmd.repr(type), repr(vals) if hasattr(self, name): func = getattr(self, name) try: rvals = func(type, tag, vals) except ServError, e: self._err(tag, e.args[0]) return 1 # nonfatal if self.verbose: print cmd.repr(type+1), repr(rvals) self.msg.send(type + 1, tag, *rvals) else: return self._err(tag, "Unhandled message: %s" % cmd.repr(type)) return 1 def serve(self): while self.rpc(): pass