int writeInternal2(ChannelFD fd, byte[] bufBytes, int buf, int count) { return posix.write(fd, bufBytes, buf, count, nonblock); }
int writeInternal2(ChannelFD fd, byte[] bufBytes, int buf, int count) { return posix.write(fd, bufBytes, buf, count, nonblock); }
private int flushBufferSync() { int l = writableLength(wbuf.len); int r = posix.write(fd, wbuf.ptr, wbuf.off, l, nonblock); if (wbuf.len <= r) { wbuf.off = 0; wbuf.len = 0; return 0; } if (0 <= r) { wbuf.off += r; wbuf.len -= r; posix.errno = Errno.EAGAIN; } return -1; }
private int flushBufferSync() { int l = writableLength(wbuf.len); int r = posix.write(fd, wbuf.ptr, wbuf.off, l, nonblock); if (wbuf.len <= r) { wbuf.off = 0; wbuf.len = 0; return 0; } if (0 <= r) { wbuf.off += r; wbuf.len -= r; posix.errno = Errno.EAGAIN; } return -1; }
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); }