public void checkCharReadable(ThreadContext context) { checkClosed(); if ((mode & READABLE) == 0) { throw runtime.newIOError("not opened for reading"); } if (wbuf.len != 0) { if (io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(posix.errno, "error flushing"); } } if (tiedIOForWriting != null) { OpenFile wfptr; wfptr = tiedIOForWriting.getOpenFileChecked(); if (wfptr.io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(wfptr.posix.errno, wfptr.getPath()); } } }
public void checkCharReadable(ThreadContext context) { checkClosed(); if ((mode & READABLE) == 0) { throw runtime.newIOError("not opened for reading"); } if (wbuf.len != 0) { if (io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(posix.errno, "error flushing"); } } if (tiedIOForWriting != null) { OpenFile wfptr; wfptr = tiedIOForWriting.getOpenFileChecked(); if (wfptr.io_fflush(context) < 0) { throw runtime.newErrnoFromErrno(wfptr.posix.errno, wfptr.getPath()); } } }
private void flushBeforeSeek(ThreadContext context) { boolean locked = lock(); try { if (io_fflush(context) < 0) throw context.runtime.newErrnoFromErrno(posix.errno, ""); unread(context); posix.errno = null; } finally { if (locked) unlock(); } }
private void flushBeforeSeek(ThreadContext context) { boolean locked = lock(); try { if (io_fflush(context) < 0) throw context.runtime.newErrnoFromErrno(posix.errno, ""); unread(context); posix.errno = null; } finally { if (locked) unlock(); } }
if (io_fflush(context) < 0) return -1L; if (n == 0) return len;
if (io_fflush(context) < 0) return -1L; if (n == 0) return len;
private static RubyIO getRubyIO(Ruby runtime, Writer writer) { PrintStream stream = new PrintStream(new WriterOutputStream(writer, runtime.getDefaultCharset().name()), true); RubyIO io = new RubyIO(runtime, stream, false); boolean locked = io.getOpenFile().lock(); try { io.getOpenFile().setSync(true); io.getOpenFile().io_fflush(runtime.getCurrentContext()); return io; } finally { if (locked) io.getOpenFile().unlock(); } }
private static RubyIO getRubyIO(Ruby runtime, Writer writer) { PrintStream stream = new PrintStream(new WriterOutputStream(writer, runtime.getDefaultCharset().name()), true); RubyIO io = new RubyIO(runtime, stream, false); boolean locked = io.getOpenFile().lock(); try { io.getOpenFile().setSync(true); io.getOpenFile().io_fflush(runtime.getCurrentContext()); return io; } finally { if (locked) io.getOpenFile().unlock(); } }
try { if ((fptr.getMode() & OpenFile.WRITABLE) != 0) { if (fptr.io_fflush(context) < 0) throw context.runtime.newErrnoFromErrno(fptr.errno(), "");
try { if ((fptr.getMode() & OpenFile.WRITABLE) != 0) { if (fptr.io_fflush(context) < 0) throw context.runtime.newErrnoFromErrno(fptr.errno(), "");
if (io_fflush(context) < 0 && err == context.nil) { err = RubyFixnum.newFixnum(runtime, posix.errno == null ? 0 :posix.errno.longValue());
@JRubyMethod public RubyFixnum fsync(ThreadContext context) { Ruby runtime = context.runtime; OpenFile fptr; RubyIO io = GetWriteIO(); fptr = io.getOpenFileChecked(); if (fptr.io_fflush(context) < 0) throw runtime.newSystemCallError(""); if (!Platform.IS_WINDOWS) { /* already called in io_fflush() */ try { if (fptr.fileChannel() != null) fptr.fileChannel().force(true); if (fptr.fd().chNative != null) { int ret = runtime.getPosix().fsync(fptr.fd().chNative.getFD()); if (ret < 0) throw runtime.newErrnoFromInt(runtime.getPosix().errno()); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } } return RubyFixnum.zero(runtime); }
if (io_fflush(context) < 0 && err == context.nil) { err = RubyFixnum.newFixnum(runtime, posix.errno == null ? 0 :posix.errno.longValue());
@JRubyMethod public RubyFixnum fsync(ThreadContext context) { Ruby runtime = context.runtime; OpenFile fptr; RubyIO io = GetWriteIO(); fptr = io.getOpenFileChecked(); if (fptr.io_fflush(context) < 0) throw runtime.newSystemCallError(""); if (!Platform.IS_WINDOWS) { /* already called in io_fflush() */ try { if (fptr.fileChannel() != null) fptr.fileChannel().force(true); if (fptr.fd().chNative != null) { int ret = runtime.getPosix().fsync(fptr.fd().chNative.getFD()); if (ret < 0) throw runtime.newErrnoFromInt(runtime.getPosix().errno()); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } } return RubyFixnum.zero(runtime); }
private IRubyObject ioWriteNonblock(ThreadContext context, Ruby runtime, IRubyObject str, boolean no_exception) { OpenFile fptr; long n; if (!(str instanceof RubyString)) str = str.asString(); RubyIO io = GetWriteIO(); fptr = io.getOpenFileChecked(); boolean locked = fptr.lock(); try { fptr.checkWritable(context); if (fptr.io_fflush(context) < 0) throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); fptr.setNonblock(runtime); ByteList strByteList = ((RubyString) str).getByteList(); n = fptr.posix.write(fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), strByteList.getRealSize(), true); if (n == -1) { if (fptr.posix.errno == Errno.EWOULDBLOCK || fptr.posix.errno == Errno.EAGAIN) { if (no_exception) { return runtime.newSymbol("wait_writable"); } else { throw runtime.newErrnoEAGAINWritableError("write would block"); } } throw runtime.newErrnoFromErrno(fptr.posix.errno, fptr.getPath()); } } finally { if (locked) fptr.unlock(); } return runtime.newFixnum(n); }
private IRubyObject ioWriteNonblock(ThreadContext context, Ruby runtime, IRubyObject str, boolean no_exception) { OpenFile fptr; long n; if (!(str instanceof RubyString)) str = str.asString(); RubyIO io = GetWriteIO(); fptr = io.getOpenFileChecked(); boolean locked = fptr.lock(); try { fptr.checkWritable(context); if (fptr.io_fflush(context) < 0) throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath()); fptr.setNonblock(runtime); ByteList strByteList = ((RubyString) str).getByteList(); n = fptr.posix.write(fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), strByteList.getRealSize(), true); if (n == -1) { if (fptr.posix.errno == Errno.EWOULDBLOCK || fptr.posix.errno == Errno.EAGAIN) { if (no_exception) { return runtime.newSymbol("wait_writable"); } else { throw runtime.newErrnoEAGAINWritableError("write would block"); } } throw runtime.newErrnoFromErrno(fptr.posix.errno, fptr.getPath()); } } finally { if (locked) fptr.unlock(); } return runtime.newFixnum(n); }
while (res == EConvResult.DestinationBufferFull) { if (wbuf.len == wbuf.capa) { if (io_fflush(context) < 0) return noalloc ? context.tru : runtime.newFixnum(posix.errno == null ? 0 : posix.errno.longValue());
while (res == EConvResult.DestinationBufferFull) { if (wbuf.len == wbuf.capa) { if (io_fflush(context) < 0) return noalloc ? context.tru : runtime.newFixnum(posix.errno == null ? 0 : posix.errno.longValue());