36f8f6fb024b20cc523cdf9ebde7491eca84fd7c markd Sun Dec 6 20:33:20 2020 -0800 multiple request per connect works except hgBlat diff --git src/lib/gfNet.c src/lib/gfNet.c index 9259d14..203e1fc 100644 --- src/lib/gfNet.c +++ src/lib/gfNet.c @@ -1,47 +1,80 @@ /* gfNet.c - Network dependent stuff for blat server. */ /* Copyright (C) 2011 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include "common.h" #include "errAbort.h" #include "genoFind.h" #include "net.h" -struct gfConnection *gfMayConnect(char *hostName, char *portName) +struct gfConnection *gfMayConnect(char *hostName, char *portName, boolean isDynamic) /* Start connection with server or return -1. */ { /* Connect to server. */ -int sd = netConnect(hostName, atoi(portName)); +int port = atoi(portName); +int sd = netConnect(hostName, port); // if error, sd == -1 if (sd < 0) return NULL; struct gfConnection *conn; AllocVar(conn); conn->fd = sd; +conn->hostName = cloneString(hostName); +conn->port = port; +conn->isDynamic = isDynamic; return conn; } -struct gfConnection *gfConnect(char *hostName, char *portName) +struct gfConnection *gfConnect(char *hostName, char *portName, boolean isDynamic) /* Start connection with server. Abort on error. */ { /* Connect to server. */ -struct gfConnection *conn = gfMayConnect(hostName, portName); +struct gfConnection *conn = gfMayConnect(hostName, portName, isDynamic); if (conn == NULL) { errnoAbort("Sorry, the BLAT/iPCR server seems to be down. Please try " - "again later."); + "again later: %s %s", hostName, portName); } return conn; } +void gfBeginRequest(struct gfConnection *conn) +/* called before a request is started. If the connect is not open, reopen + * it. */ +{ +if (conn->fd < 0) + { + conn->fd = netConnect(conn->hostName, conn->port); + if (conn->fd < 0) + errnoAbort("Sorry, the BLAT/iPCR server seems to be down. Please try " + "again later: %s %d", conn->hostName, conn->port); + } +} + +void gfEndRequest(struct gfConnection *conn) +/* End a request that might be followed by another requests. For + * a static server, this closed the connection. A dynamic server + * it is left open. */ +{ +if (!conn->isDynamic) + { + close(conn->fd); + conn->fd = -1; + } +} + + void gfDisconnect(struct gfConnection **pConn) /* Disconnect from server */ { -if (*pConn != NULL) +struct gfConnection *conn = *pConn; +if (conn != NULL) { - close((*pConn)->fd); + if (conn->fd >= 0) + close(conn->fd); + freeMem(conn->hostName); freez(pConn); } }