Пример #1
0
def writeSetContentsCB(fs):
    try:
        with ruv.unstashingFS(fs) as (vat, sc):
            assert isinstance(sc, SetContents)
            size = intmask(fs.c_result)
            if size > 0:
                sc.written(size)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sc.fail(u"libuv error: %s" % msg)
    except:
        print "Exception in writeSetContentsCB"
Пример #2
0
def writeSetContentsCB(fs):
    try:
        with ruv.unstashingFS(fs) as (vat, sc):
            assert isinstance(sc, SetContents)
            size = intmask(fs.c_result)
            if size > 0:
                sc.written(size)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sc.fail(u"libuv error: %s" % msg)
    except:
        print "Exception in writeSetContentsCB"
Пример #3
0
def writeCB(fs):
    try:
        with ruv.unstashingFS(fs) as (vat, drain):
            assert isinstance(drain, FileDrain)
            size = intmask(fs.c_result)
            if size > 0:
                drain.written(size)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                drain.abort(u"libuv error: %s" % msg)
    except:
        print "Exception in writeCB"
Пример #4
0
def writeCB(fs):
    try:
        with ruv.unstashingFS(fs) as (vat, drain):
            assert isinstance(drain, FileDrain)
            size = intmask(fs.c_result)
            if size > 0:
                drain.written(size)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                drain.abort(u"libuv error: %s" % msg)
    except:
        print "Exception in writeCB"
Пример #5
0
def writeFileCB(fs):
    try:
        with ruv.unstashingFS(fs) as (vat, sink):
            assert isinstance(sink, FileSink)
            size = intmask(fs.c_result)
            if size > 0:
                # XXX backpressure drain.written(size)
                pass
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                sink.abort(StrObject(u"libuv error: %s" % msg))
    except:
        print "Exception in writeFileCB"
Пример #6
0
def openSetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        with ruv.unstashingFS(fs) as (vat, sc):
            assert isinstance(sc, SetContents)
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                sc.fail(u"Couldn't open file fount: %s" % msg)
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                sc.startWriting(fd, fs)
    except:
        print "Exception in openSetContentsCB"
Пример #7
0
def openSetContentsCB(fs):
    try:
        fd = intmask(fs.c_result)
        with ruv.unstashingFS(fs) as (vat, sc):
            assert isinstance(sc, SetContents)
            if fd < 0:
                msg = ruv.formatError(fd).decode("utf-8")
                sc.fail(u"Couldn't open file fount: %s" % msg)
                # Done with fs.
                ruv.fsDiscard(fs)
            else:
                sc.startWriting(fd, fs)
    except:
        print "Exception in openSetContentsCB"
Пример #8
0
def readFileCB(fs):
    size = intmask(fs.c_result)
    with ruv.unstashingFS(fs) as (vat, source):
        assert isinstance(source, FileSource)
        with scopedVat(vat):
            if size > 0:
                data = charpsize2str(source._buf.c_base, size)
                source.deliver(data)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                source.abort(u"libuv error: %s" % msg)
            else:
                # EOF.
                source.complete()
Пример #9
0
def readCB(fs):
    # Does *not* invoke user code.
    try:
        size = intmask(fs.c_result)
        with ruv.unstashingFS(fs) as (vat, fount):
            assert isinstance(fount, FileFount)
            # Done with fs, but don't free it; it belongs to the fount.
            if size > 0:
                data = charpsize2str(fount.buf.c_base, size)
                fount.receive(data)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                fount.abort(u"libuv error: %s" % msg)
            else:
                fount.stop(u"End of file")
    except:
        print "Exception in readCB"
Пример #10
0
def readCB(fs):
    # Does *not* invoke user code.
    try:
        size = intmask(fs.c_result)
        with ruv.unstashingFS(fs) as (vat, fount):
            assert isinstance(fount, FileFount)
            # Done with fs, but don't free it; it belongs to the fount.
            if size > 0:
                data = charpsize2str(fount.buf.c_base, size)
                fount.receive(data)
            elif size < 0:
                msg = ruv.formatError(size).decode("utf-8")
                fount.abort(u"libuv error: %s" % msg)
            else:
                fount.stop(u"End of file")
    except:
        print "Exception in readCB"