Exemplo n.º 1
0
def connectCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        fountResolver, drainResolver = unwrapList(resolvers)
        assert isinstance(fountResolver, LocalResolver)
        assert isinstance(drainResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                fountResolver.resolve(StreamFount(stream, vat))
                drainResolver.resolve(StreamDrain(stream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                fountResolver.smash(StrObject(error.decode("utf-8")))
                drainResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
Exemplo n.º 2
0
def connectStreamCB(connect, status):
    status = intmask(status)
    stream = connect.c_handle

    try:
        vat, resolvers = ruv.unstashStream(stream)
        sourceResolver, sinkResolver = unwrapList(resolvers)
        assert isinstance(sourceResolver, LocalResolver)
        assert isinstance(sinkResolver, LocalResolver)

        with scopedVat(vat):
            if status >= 0:
                debug_print("Made connection!")
                wrappedStream = ruv.wrapStream(stream, 2)
                sourceResolver.resolve(StreamSource(wrappedStream, vat))
                sinkResolver.resolve(StreamSink(wrappedStream, vat))
            else:
                error = "Connection failed: " + ruv.formatError(status)
                debug_print(error)
                sourceResolver.smash(StrObject(error.decode("utf-8")))
                sinkResolver.smash(StrObject(error.decode("utf-8")))
                # Done with stream.
                ruv.closeAndFree(stream)
    except:
        if not we_are_translated():
            raise
Exemplo n.º 3
0
def readStreamCB(stream, status, buf):
    status = intmask(status)
    # We only restash in the success case, not the error cases.
    vat, source = ruv.unstashStream(stream)
    assert isinstance(source, StreamSource), "Implementation error"
    # Don't read any more. We'll call .readStart() when we're interested in
    # reading again.
    ruv.readStop(stream)
    with scopedVat(vat):
        if status > 0:
            # Restash required.
            ruv.stashStream(stream, (vat, source))
            data = charpsize2str(buf.c_base, status)
            source.deliver(data)
        elif status == -4095:
            # EOF.
            source.complete()
        else:
            msg = ruv.formatError(status).decode("utf-8")
            source.abort(u"libuv error: %s" % msg)
Exemplo n.º 4
0
def readStreamCB(stream, status, buf):
    status = intmask(status)
    # We only restash in the success case, not the error cases.
    vat, source = ruv.unstashStream(stream)
    assert isinstance(source, StreamSource), "Implementation error"
    # Don't read any more. We'll call .readStart() when we're interested in
    # reading again.
    ruv.readStop(stream)
    with scopedVat(vat):
        if status > 0:
            # Restash required.
            ruv.stashStream(stream, (vat, source))
            data = charpsize2str(buf.c_base, status)
            source.deliver(data)
        elif status == -4095:
            # EOF.
            source.complete()
        else:
            msg = ruv.formatError(status).decode("utf-8")
            source.abort(u"libuv error: %s" % msg)
Exemplo n.º 5
0
def readCB(stream, status, buf):
    status = intmask(status)
    try:
        # We only restash in the success case, not the error cases.
        vat, fount = ruv.unstashStream(stream)
        assert isinstance(fount, StreamFount), "Implementation error"
        with scopedVat(vat):
            if status > 0:
                # Restash required.
                ruv.stashStream(stream, (vat, fount))
                data = charpsize2str(buf.c_base, status)
                fount.receive(data)
            elif status == 0:
                # EOF.
                fount.stop(u"End of stream")
            else:
                msg = ruv.formatError(status).decode("utf-8")
                fount.abort(u"libuv error: %s" % msg)
    except:
        if not we_are_translated():
            raise