public void write()

in src/com/pty4j/windows/winpty/NamedPipe.java [114:148]


  public void write(byte[] buf, int off, int len) {
    if (buf == null) {
      throw new NullPointerException();
    }
    if (off < 0 || len < 0 || len > buf.length - off) {
      throw new IndexOutOfBoundsException();
    }
    writeLock.lock();
    try {
      if (shutdownFlag) {
        return;
      }
      if (len == 0) {
        return;
      }
      if (writeBuffer.size() < len) {
        writeBuffer = new Memory(len);
      }
      writeBuffer.write(0, buf, off, len);
      writeOver.hEvent = writeEvent;
      writeOver.write();
      writeActual.setValue(0);
      boolean success = KERNEL32.WriteFile(myHandle, writeBuffer, len, writeActual, writeOver.getPointer());
      if (!success && Native.getLastError() == WinNT.ERROR_IO_PENDING) {
        int waitRet = Kernel32.INSTANCE.WaitForMultipleObjects(
                writeWaitHandles.length, writeWaitHandles, false, WinNT.INFINITE);
        if (waitRet != WinNT.WAIT_OBJECT_0) {
          KERNEL32.CancelIo(myHandle);
        }
        KERNEL32.GetOverlappedResult(myHandle, writeOver.getPointer(), writeActual, true);
      }
    } finally {
      writeLock.unlock();
    }
  }