641129ea4df7d116ea619a10c02086b7cb446e00
kent
  Thu Apr 25 09:32:26 2013 -0700
Making new library function netWaitForData that is a minor refactoring of a private existing net.c function.
diff --git src/lib/net.c src/lib/net.c
index 47d55c3..50eba15 100644
--- src/lib/net.c
+++ src/lib/net.c
@@ -556,68 +556,75 @@
     dyStringAppend(dy, ":");
     dyStringAppend(dy, npu->port);
     }
 dyStringAppend(dy, npu->file);
 if (npu->byteRangeStart != -1)
     {
     dyStringPrintf(dy, ";byterange=%lld-", (long long)npu->byteRangeStart);
     if (npu->byteRangeEnd != -1)
 	dyStringPrintf(dy, "%lld", (long long)npu->byteRangeEnd);
     }
 
 /* Clean up and return handle. */
 return dyStringCannibalize(&dy);
 }
 
-/* this was cloned from rudp.c - move it later for sharing */
-static boolean readReadyWait(int sd, int microseconds)
-/* Wait for descriptor to have some data to read, up to
- * given number of microseconds. */
+int netWaitForData(int sd, int microseconds)
+/* Wait for descriptor to have some data to read, up to given number of
+ * number of microseconds.  Returns amount of data there or zero if timed out. */
 {
 struct timeval tv;
 fd_set set;
 int readyCount;
 
 for (;;)
     {
     if (microseconds >= 1000000)
 	{
 	tv.tv_sec = microseconds/1000000;
 	tv.tv_usec = microseconds%1000000;
 	}
     else
 	{
 	tv.tv_sec = 0;
 	tv.tv_usec = microseconds;
 	}
     FD_ZERO(&set);
     FD_SET(sd, &set);
     readyCount = select(sd+1, &set, NULL, NULL, &tv);
     if (readyCount < 0) 
 	{
 	if (errno == EINTR)	/* Select interrupted, not timed out. */
 	    continue;
     	else 
-    	    warn("select failure in rudp: %s", strerror(errno));
+    	    warn("select failure %s", strerror(errno));
     	}
     else
 	{
-    	return readyCount > 0;	/* Zero readyCount indicates time out */
+    	return readyCount;	/* Zero readyCount indicates time out */
 	}
     }
 }
 
+static boolean readReadyWait(int sd, int microseconds)
+/* Wait for descriptor to have some data to read, up to given number of
+ * number of microseconds.  Returns true if there is data, false if timed out. */
+{
+int readyCount = netWaitForData(sd, microseconds);
+return readyCount > 0;	/* Zero readyCount indicates time out */
+}
+
 static void sendFtpCommandOnly(int sd, char *cmd)
 /* send command to ftp server */
 {   
 mustWriteFd(sd, cmd, strlen(cmd));
 }
 
 #define NET_FTP_TIMEOUT 1000000
 
 static boolean receiveFtpReply(int sd, char *cmd, struct dyString **retReply, int *retCode)
 /* send command to ftp server and check resulting reply code, 
  * warn and return FALSE if not desired reply.  If retReply is non-NULL, store reply text there. */
 {
 char *startLastLine = NULL;
 struct dyString *rs = newDyString(4*1024);
 while (1)