in src/com/pty4j/windows/winpty/NamedPipe.java [70:109]
public int read(byte[] buf, int off, int len) {
if (buf == null) {
throw new NullPointerException();
}
if (off < 0 || len < 0 || len > buf.length - off) {
throw new IndexOutOfBoundsException();
}
readLock.lock();
try {
if (shutdownFlag) {
return -1;
}
if (len == 0) {
return 0;
}
if (readBuffer.size() < len) {
readBuffer = new Memory(len);
}
readOver.hEvent = readEvent;
readOver.write();
readActual.setValue(0);
boolean success = KERNEL32.ReadFile(myHandle, readBuffer, len, readActual, readOver.getPointer());
if (!success && Native.getLastError() == WinNT.ERROR_IO_PENDING) {
int waitRet = Kernel32.INSTANCE.WaitForMultipleObjects(
readWaitHandles.length, readWaitHandles, false, WinNT.INFINITE);
if (waitRet != WinNT.WAIT_OBJECT_0) {
KERNEL32.CancelIo(myHandle);
}
success = KERNEL32.GetOverlappedResult(myHandle, readOver.getPointer(), readActual, true);
}
int actual = readActual.getValue();
if (!success || actual <= 0) {
return -1;
}
readBuffer.read(0, buf, off, actual);
return actual;
} finally {
readLock.unlock();
}
}