src/lib/udc.c 1.36

1.36 2010/03/10 23:44:05 angie
Instead of errAborting in low-level net.c routines, pass errors up to higher-level code, most of which already checks for error return values.
Index: src/lib/udc.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/udc.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -b -B -U 4 -r1.35 -r1.36
--- src/lib/udc.c	25 Feb 2010 22:55:55 -0000	1.35
+++ src/lib/udc.c	10 Mar 2010 23:44:05 -0000	1.36
@@ -131,11 +131,12 @@
 }
 
 static int connInfoGetSocket(struct connInfo *ci, char *url, bits64 offset, int size)
 /* If ci has an open socket and the given offset matches ci's current offset,
- * reuse ci->socket.  Otherwise close the socket, open a new one, and update ci. */
+ * reuse ci->socket.  Otherwise close the socket, open a new one, and update ci,
+ * or return -1 if there is an error opening a new one. */
 {
-if (ci != NULL && ci->socket != 0 && ci->offset != offset)
+if (ci != NULL && ci->socket > 0 && ci->offset != offset)
     {
     bits64 skipSize = (offset - ci->offset);
     if (skipSize > 0 && skipSize <= MAX_SKIP_TO_SAVE_RECONNECT)
 	{
@@ -146,15 +147,15 @@
     else
 	{
 	verbose(2, "Offset mismatch (ci %lld != new %lld), reopening.\n", ci->offset, offset);
 	mustCloseFd(&(ci->socket));
-	if (ci->ctrlSocket != 0)
+	if (ci->ctrlSocket > 0)
 	    mustCloseFd(&(ci->ctrlSocket));
 	ZeroVar(ci);
 	}
     }
 int sd;
-if (ci == NULL || ci->socket == 0)
+if (ci == NULL || ci->socket <= 0)
     {
     char rangeUrl[2048];
     if (ci == NULL)
 	{
@@ -167,14 +168,16 @@
 	safef(rangeUrl, sizeof(rangeUrl), "%s;byterange=%lld-", url, offset);
 	sd = ci->socket = netUrlOpenSockets(rangeUrl, &(ci->ctrlSocket));
 	ci->offset = offset;
 	}
+    if (sd < 0)
+	return -1;
     if (startsWith("http", url))
 	{
 	char *newUrl = NULL;
 	int newSd = 0;
 	if (!netSkipHttpHeaderLinesHandlingRedirect(sd, url, &newSd, &newUrl))
-	    errAbort("Couldn't open %s", url);   // do we really want errAbort here?
+	    return -1;
 	if (newUrl)  // not sure redirection will work with byte ranges as it is now
 	    {
 	    freeMem(newUrl); 
 	    sd = newSd;
@@ -184,10 +187,8 @@
 	}
     }
 else
     sd = ci->socket;
-if (sd < 0)
-    errnoAbort("Couldn't open %s", url);   // do we really want errAbort here?
 return sd;
 }
 
 /********* Section for local file protocol **********/
@@ -326,8 +327,10 @@
 else
     errAbort("Invalid protocol in url [%s] in udcDataViaFtp, only http, https, or ftp supported",
 	     url); 
 int sd = connInfoGetSocket(ci, url, offset, size);
+if (sd < 0)
+    errAbort("Can't get data socket for %s", url);
 int rd = 0, total = 0, remaining = size;
 char *buf = (char *)buffer;
 while ((remaining > 0) && ((rd = read(sd, buf, remaining)) > 0))
     {