/** @inheritDoc */ public int writeBuf(int fd, byte buffer[], int off, int len) throws IOException { int result = 0; byte[] buf = buffer; if (off != 0) { buf = new byte[len]; System.arraycopy(buffer, off, buf, 0, len); } if (DEBUG) { System.err.println("writeBuf(" + fd + ") before write."); } result = libc.write(fd, buf, len); // We rely on open0() for setting the socket to non-blocking if (result < 0) { int err_code = LibCUtil.errno(); if (err_code == LibC.EWOULDBLOCK) { VMThread.getSystemEvents().waitForWriteEvent(fd); if (DEBUG) { System.err.println("writeBuf(" + fd + ") returned from select. retry."); } result = libc.write(fd, buf, len); // We rely on open0() for setting the socket to non-blocking } if (DEBUG) { System.err.println("writeBuf(" + fd + ") error:"); } LibCUtil.errCheckNeg(result); } return result; }