Add a reference count to struct fetchconn so we don't prematurely close and
free a cached FTP connection.
This commit is contained in:
parent
ddd16e87d0
commit
f606d589b9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=98117
@ -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);
|
||||
|
@ -58,6 +58,7 @@ struct fetchconn {
|
||||
X509 *ssl_cert; /* server certificate */
|
||||
SSL_METHOD *ssl_meth; /* SSL method */
|
||||
#endif
|
||||
int ref; /* reference count */
|
||||
};
|
||||
|
||||
/* Structure used for error message lists */
|
||||
@ -74,6 +75,7 @@ int _fetch_default_port(const char *);
|
||||
int _fetch_default_proxy_port(const char *);
|
||||
conn_t *_fetch_connect(const char *, int, int, int);
|
||||
conn_t *_fetch_reopen(int);
|
||||
conn_t *_fetch_ref(conn_t *);
|
||||
int _fetch_ssl(conn_t *, int);
|
||||
ssize_t _fetch_read(conn_t *, char *, size_t);
|
||||
int _fetch_getln(conn_t *);
|
||||
|
@ -874,7 +874,7 @@ _ftp_cached_connect(struct url *url, struct url *purl, const char *flags)
|
||||
return (NULL);
|
||||
if (cached_connection)
|
||||
_ftp_disconnect(cached_connection);
|
||||
cached_connection = conn;
|
||||
cached_connection = _fetch_ref(conn);
|
||||
memcpy(&cached_host, url, sizeof *url);
|
||||
return (conn);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user