def renameCB(fs): try: success = intmask(fs.c_result) vat, r = ruv.unstashFS(fs) if success < 0: msg = ruv.formatError(success).decode("utf-8") r.smash(StrObject(u"Couldn't rename file: %s" % msg)) else: r.resolve(NullObject) # Done with fs. ruv.fsDiscard(fs) except: print "Exception in renameCB"
def closeSetContentsCB(fs): try: vat, sc = ruv.unstashFS(fs) # Need to scope vat here. with scopedVat(vat): assert isinstance(sc, SetContents) size = intmask(fs.c_result) if size < 0: msg = ruv.formatError(size).decode("utf-8") sc.fail(u"libuv error: %s" % msg) else: # Success. sc.rename() except: print "Exception in closeSetContentsCB"
def readFileCB(fs): size = intmask(fs.c_result) vat, source = ruv.unstashFS(fs) 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() ruv.fsDiscard(fs)
def openDrainCB(fs): # As above. try: fd = intmask(fs.c_result) vat, r = ruv.unstashFS(fs) assert isinstance(r, LocalResolver) with scopedVat(vat): if fd < 0: msg = ruv.formatError(fd).decode("utf-8") r.smash(StrObject(u"Couldn't open file drain: %s" % msg)) # Done with fs. ruv.fsDiscard(fs) else: r.resolve(FileDrain(fs, fd, vat)) except: print "Exception in openDrainCB"
def writeFileCB(fs): try: vat, sb = ruv.unstashFS(fs) sink = sb.obj 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)) sb.deallocate() ruv.fsDiscard(fs) except: print "Exception in writeFileCB"
def openFountCB(fs): # Does *not* run user-level code. The scoped vat is only for promise # resolution. try: fd = intmask(fs.c_result) vat, r = ruv.unstashFS(fs) assert isinstance(r, LocalResolver) with scopedVat(vat): if fd < 0: msg = ruv.formatError(fd).decode("utf-8") r.smash(StrObject(u"Couldn't open file fount: %s" % msg)) # Done with fs. ruv.fsDiscard(fs) else: r.resolve(FileFount(fs, fd, vat)) except: print "Exception in openFountCB"
def getContentsCB(fs): try: size = intmask(fs.c_result) # Don't use with-statements here; instead, each next action in # GetContents will re-stash if necessary. ~ C. vat, self = ruv.unstashFS(fs) assert isinstance(self, GetContents) if size > 0: data = charpsize2str(self.buf.c_base, size) self.append(data) elif size < 0: msg = ruv.formatError(size).decode("utf-8") self.fail(msg) else: # End of file! Complete the callback. self.succeed() except Exception: print "Exception in getContentsCB"
def openGetContentsCB(fs): try: fd = intmask(fs.c_result) vat, r = ruv.unstashFS(fs) assert isinstance(r, LocalResolver) with scopedVat(vat): if fd < 0: msg = ruv.formatError(fd).decode("utf-8") r.smash(StrObject(u"Couldn't open file fount: %s" % msg)) # Done with fs. ruv.fsDiscard(fs) else: # Strategy: Read and use the callback to queue additional reads # until done. This call is known to its caller to be expensive, so # there's not much point in trying to be clever about things yet. gc = GetContents(vat, fs, fd, r) gc.queueRead() except: print "Exception in openGetContentsCB"