Пример #1
0
    def recv(self):
        """
        Receive a request message from the client
        """
        msgdata = (c_ubyte * NORM_MSG_SIZE)()
        msg = mempair(p9msg, msgdata)
        (baddr, blen) = msg.databuf()
        l = libc.recv(self.__clsock, baddr, blen, 0)
        hdr = msg.car()
        if l > sizeof(hdr):
            if hdr.size > l:
                if hdr.size > MAX_MSG_SIZE:
                    raise IOError("The message is too large: %d bytes" %
                                  hdr.size)
                resize(msgdata, hdr.size)
                (baddr, blen) = msg.databuf()
                l2 = libc.recv(self.__clsock, baddr + hdr.size - l, blen - l,
                               0)
                if l2 > 0:
                    l += l2
                else:
                    raise IOError("Unable to read the %d remaining bytes" %
                                  blen - l)
        else:
            raise IOError("Unable to read the message")

        return (l, msg)
Пример #2
0
Файл: core.py Проект: svinota/cx
    def recv(self,socket):
        """
        """
        msg = p9msg()
        l = libc.recv(socket, byref(msg), sizeof(msg), 0)

        return (l,msg)
Пример #3
0
    def recv(self):
        """
        Receive a request message from the client
        """
        msgdata = (c_ubyte * NORM_MSG_SIZE)()
        msg = mempair(p9msg, msgdata)
        (baddr, blen) = msg.databuf()
        l = libc.recv(self.__clsock, baddr, blen, 0)
        hdr = msg.car()
        if l > sizeof(hdr):
            if hdr.size > l:
                if hdr.size > MAX_MSG_SIZE:
                    raise IOError ("The message is too large: %d bytes" % hdr.size)
                resize(msgdata, hdr.size)
                (baddr, blen) = msg.databuf()
                l2 = libc.recv(self.__clsock, baddr + hdr.size - l, blen - l, 0)
                if l2 > 0:
                    l += l2
                else:
                    raise IOError ("Unable to read the %d remaining bytes" % blen - l)
        else:
            raise IOError ("Unable to read the message")

        return (l, msg)