Esempio n. 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)
Esempio n. 2
0
def basereply(tmsg, rtype=-1):
    """
    Returns the corresponding R-message mempair object for
    a given T-message mempair object
    """
    if rtype < 0:
        rtype = tmsg.type + 1
    msgdata = (c_ubyte * NORM_MSG_SIZE)()
    replymsg = mempair(p9msg, msgdata)
    replymsg.type = rtype
    replymsg.tag = tmsg.tag
    (baddr, bsize) = replymsg.carbuf()
    replymsg.size = bsize

    return replymsg
Esempio n. 3
0
def basereply (tmsg, rtype = -1):
    """
    Returns the corresponding R-message mempair object for
    a given T-message mempair object
    """
    if rtype < 0:
        rtype = tmsg.type + 1
    msgdata = (c_ubyte * NORM_MSG_SIZE)()
    replymsg = mempair(p9msg, msgdata)
    replymsg.type = rtype
    replymsg.tag = tmsg.tag
    (baddr, bsize) = replymsg.carbuf()
    replymsg.size = bsize
    
    return replymsg
Esempio n. 4
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)