in nailgun-server/src/main/java/com/facebook/nailgun/NGCommunicator.java [553:579]
int receive(byte[] b, int offset, int length) throws IOException, InterruptedException {
synchronized (readLock) {
if (remaining > 0) {
int bytesToRead = Math.min(remaining, length);
int result = stdin.read(b, offset, bytesToRead);
remaining -= result;
return result;
}
if (eof) {
return -1;
}
}
// make client know we want more data!
sendSendInput();
synchronized (readLock) {
if (remaining == 0 && !eof) {
readLock.wait();
}
// at this point we should have data so call itself recursively to utilize
// reentrant lock
return receive(b, offset, length);
}
}