in nailgun-client/c/ng.c [307:347]
void recvToFD(HANDLE destFD, char *buf, unsigned long len) {
unsigned long bytesRead = 0;
int bytesCopied;
while (bytesRead < len) {
unsigned long bytesRemaining = len - bytesRead;
int bytesToRead = (BUFSIZE < bytesRemaining) ? BUFSIZE : bytesRemaining;
int thisPass = 0;
thisPass = recv(nailgunsocket, buf, bytesToRead, MSG_WAITALL);
if (thisPass == 0 || thisPass == -1) {
perror("recv");
handleSocketClose();
}
bytesRead += thisPass;
bytesCopied = 0;
while(bytesCopied < thisPass) {
#ifdef WIN32
DWORD thisWrite = 0;
WriteFile(destFD, buf + bytesCopied, thisPass - bytesCopied,
&thisWrite, NULL);
if (thisWrite < 0) {
break;
}
bytesCopied += thisWrite;
#else
int bytesWritten = write(destFD, buf + bytesCopied, thisPass - bytesCopied);
if (bytesWritten == -1) {
perror("write");
handleSocketClose();
}
bytesCopied += bytesWritten;
#endif
}
}
}