summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/common.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2002-06-11 11:27:28 +0000
committerdes <des@FreeBSD.org>2002-06-11 11:27:28 +0000
commit5064d0b266233c22e85f5845aaf1aa68ebee7d88 (patch)
treec30b6b79c2759e3145ef6c2364abfc4c383dfb65 /lib/libfetch/common.c
parentf85d0f00609e74ecc0af9af261884345400f1483 (diff)
downloadFreeBSD-src-5064d0b266233c22e85f5845aaf1aa68ebee7d88.zip
FreeBSD-src-5064d0b266233c22e85f5845aaf1aa68ebee7d88.tar.gz
Add a reference count to struct fetchconn so we don't prematurely close and
free a cached FTP connection.
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r--lib/libfetch/common.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index c234fab..2ebb296 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -195,6 +195,7 @@ _fetch_default_proxy_port(const char *scheme)
return (0);
}
+
/*
* Create a connection for an existing descriptor.
*/
@@ -207,6 +208,19 @@ _fetch_reopen(int sd)
if ((conn = calloc(1, sizeof *conn)) == NULL)
return (NULL);
conn->sd = sd;
+ ++conn->ref;
+ return (conn);
+}
+
+
+/*
+ * Bump a connection's reference count.
+ */
+conn_t *
+_fetch_ref(conn_t *conn)
+{
+
+ ++conn->ref;
return (conn);
}
@@ -319,6 +333,7 @@ _fetch_ssl(conn_t *conn, int verbose)
#endif
}
+
/*
* Read a character from a connection w/ timeout
*/
@@ -377,6 +392,7 @@ _fetch_read(conn_t *conn, char *buf, size_t len)
return (total);
}
+
/*
* Read a line of text from a connection w/ timeout
*/
@@ -483,6 +499,7 @@ _fetch_write(conn_t *conn, const char *buf, size_t len)
return (total);
}
+
/*
* Write a line of text to a connection w/ timeout
*/
@@ -504,6 +521,8 @@ _fetch_close(conn_t *conn)
{
int ret;
+ if (--conn->ref > 0)
+ return (0);
ret = close(conn->sd);
free(conn);
return (ret);
OpenPOWER on IntegriCloud