def reply(self, rmsg, task_done=True): """ Send the given reply message to the client. The size of the message is checked not to exceed the maximum message size, configured for this session. According to the 9P spec, the maximum message size is specified by the client with the T-version request. If the message is longer than a message client is ready to handle, then the Rerror message is sent and a ValueError is raised """ (baddr, blen) = rmsg.buf() rmsg.size = blen emsg = None if rmsg.size > self.msize: emsg = errorreply(rmsg, "The reply message is too long") extra = emsg.size - self.msize if extra > emsg.ename.len: extra = emsg.ename.len if extra > 0: emsg.ename.len -= extra emsg.size -= extra (baddr, blen) = emsg.buf() l = libc.send(self.__clsock, baddr, blen, 0) self.debug("%i bytes sent" % l) if l < blen: raise IOError("Unable to send the message") if task_done: self.__sock.msgdone() if emsg is not None: raise ValueError("The message is too long")
def reply (self, rmsg, task_done = True): """ Send the given reply message to the client. The size of the message is checked not to exceed the maximum message size, configured for this session. According to the 9P spec, the maximum message size is specified by the client with the T-version request. If the message is longer than a message client is ready to handle, then the Rerror message is sent and a ValueError is raised """ (baddr, blen) = rmsg.buf() rmsg.size = blen emsg = None if rmsg.size > self.msize: emsg = errorreply (rmsg, "The reply message is too long") extra = emsg.size - self.msize if extra > emsg.ename.len: extra = emsg.ename.len if extra > 0: emsg.ename.len -= extra emsg.size -= extra (baddr, blen) = emsg.buf() l = libc.send(self.__clsock, baddr, blen, 0) self.debug ("%i bytes sent" % l) if l < blen: raise IOError ("Unable to send the message") if task_done: self.__sock.msgdone() if emsg is not None: raise ValueError ("The message is too long")
def send(self, msg, size=0): """ """ l = libc.send(self.fd, byref(msg), size, 0) return l