示例#1
0
文件: impl.py 项目: maguro/pookeeper
def _invoke(socket, timeout, request, response=None, xid=None):
    oa = OutputArchive()
    if xid:
        oa.write_int(xid, 'xid')
    if request.type:
        oa.write_int(request.type, 'type')
    request.serialize(oa, 'NA')

    timeout = _write(socket, struct.pack('!i', len(oa.buffer)), timeout)
    timeout = _write(socket, oa.buffer, timeout)

    msg, timeout = _read(socket, 4, timeout)
    length = struct.unpack_from('!i', msg, 0)[0]

    msg, _ = _read(socket, length, timeout)
    ia = InputArchive(msg)

    zxid = None
    if xid:
        header = ReplyHeader(None, None, None)
        header.deserialize(ia, 'header')
        if header.xid != xid:
            raise RuntimeError('xids do not match, expected %r received %r', xid, header.xid)
        if header.zxid > 0:
            zxid = header.zxid
        if header.err:
            callback_exception = EXCEPTIONS[header.err]()
            LOGGER.debug('Received error %r', callback_exception)
            raise callback_exception

    if response:
        response.deserialize(ia, 'NA')
        LOGGER.debug('Read response %r', response)

    return zxid
示例#2
0
文件: impl.py 项目: maguro/pookeeper
def _read_header_and_body(socket, timeout):
    msg, timeout = _read(socket, 4, timeout)

    length = struct.unpack_from('!i', msg, 0)[0]

    msg, _ = _read(socket, length, timeout)
    input_archive = InputArchive(msg)

    header = ReplyHeader(None, None, None)
    header.deserialize(input_archive, 'header')

    return header, input_archive