public void write()

in nailgun-server/src/main/java/com/facebook/nailgun/NGWin32NamedPipeSocket.java [162:184]


    public void write(byte[] b, int off, int len) throws IOException {
      ByteBuffer data = ByteBuffer.wrap(b, off, len);

      WinBase.OVERLAPPED olap = new WinBase.OVERLAPPED();
      olap.hEvent = writerWaitable;
      olap.write();

      boolean immediate = API.WriteFile(handle, data, len, null, olap.getPointer());
      if (!immediate) {
        int lastError = API.GetLastError();
        if (lastError != WinError.ERROR_IO_PENDING) {
          throw new IOException("WriteFile() failed: " + lastError);
        }
      }
      IntByReference written = new IntByReference();
      if (!API.GetOverlappedResult(handle, olap.getPointer(), written, true)) {
        int lastError = API.GetLastError();
        throw new IOException("GetOverlappedResult() failed for write operation: " + lastError);
      }
      if (written.getValue() != len) {
        throw new IOException("WriteFile() wrote less bytes than requested");
      }
    }