Http.cc now uses one fewer dList.

This commit is contained in:
2026-01-09 21:53:25 -05:00
parent c245c1ba5f
commit 7fa9114984
+10 -12
View File
@@ -81,7 +81,7 @@ struct SocketData_t {
/* Data structures and functions to queue sockets that need to be /* Data structures and functions to queue sockets that need to be
* delayed due to the per host connection limit. * delayed due to the per host connection limit.
*/ */
typedef struct { struct Server_t {
char *host; char *host;
uint_t port; uint_t port;
bool https; bool https;
@@ -89,7 +89,7 @@ typedef struct {
int active_conns; int active_conns;
int running_the_queue; int running_the_queue;
Dlist *queue; Dlist *queue;
} Server_t; };
struct FdMapEntry_t { struct FdMapEntry_t {
int fd; int fd;
@@ -112,7 +112,7 @@ static Klist_t *ValidSocks = NULL; /* Active sockets list. It holds pointers to
static DilloUrl *HTTP_Proxy = NULL; static DilloUrl *HTTP_Proxy = NULL;
static char *HTTP_Proxy_Auth_base64 = NULL; static char *HTTP_Proxy_Auth_base64 = NULL;
static char *HTTP_Language_hdr = NULL; static char *HTTP_Language_hdr = NULL;
static Dlist *servers; static std::vector< Server_t * > servers;
/* TODO: If fd_map will stick around in its present form (FDs and SocketData_t) /* TODO: If fd_map will stick around in its present form (FDs and SocketData_t)
* then consider whether having both this and ValidSocks is necessary. * then consider whether having both this and ValidSocks is necessary.
@@ -142,8 +142,6 @@ int a_Http_init(void)
HTTP_Proxy_Auth_base64 = a_Misc_encode_base64(prefs.http_proxyuser); HTTP_Proxy_Auth_base64 = a_Misc_encode_base64(prefs.http_proxyuser);
*/ */
servers = dList_new(5);
return 0; return 0;
} }
@@ -1073,8 +1071,8 @@ static Server_t *Http_server_get(const char *host, uint_t port, bool https)
int i; int i;
Server_t *srv; Server_t *srv;
for (i = 0; i < dList_length(servers); i++) { for (i = 0; i < servers.size(); i++) {
srv = (Server_t*) dList_nth_data(servers, i); srv = servers.at( i );
if (port == srv->port && https == srv->https && if (port == srv->port && https == srv->https &&
!dStrAsciiCasecmp(host, srv->host)) !dStrAsciiCasecmp(host, srv->host))
@@ -1087,7 +1085,7 @@ static Server_t *Http_server_get(const char *host, uint_t port, bool https)
srv->host = dStrdup(host); srv->host = dStrdup(host);
srv->port = port; srv->port = port;
srv->https = https; srv->https = https;
dList_append(servers, srv); servers.push_back( srv );
return srv; return srv;
} }
@@ -1101,7 +1099,7 @@ static void Http_server_remove(Server_t *srv)
delete sd; delete sd;
} }
dList_free(srv->queue); dList_free(srv->queue);
dList_remove_fast(servers, srv); servers.erase( std::find( begin( servers ), end( servers ), srv ) );
dFree(srv->host); dFree(srv->host);
dFree(srv); dFree(srv);
} }
@@ -1111,15 +1109,15 @@ static void Http_servers_remove_all(void)
Server_t *srv; Server_t *srv;
SocketData_t *sd; SocketData_t *sd;
while (dList_length(servers) > 0) { while (not servers.empty()) {
srv = (Server_t*) dList_nth_data(servers, 0); srv = servers.at( 0 );
while ((sd = reinterpret_cast< SocketData_t * >( dList_nth_data(srv->queue, 0) ))) { while ((sd = reinterpret_cast< SocketData_t * >( dList_nth_data(srv->queue, 0) ))) {
dList_remove(srv->queue, sd); dList_remove(srv->queue, sd);
dFree(sd); dFree(sd);
} }
Http_server_remove(srv); Http_server_remove(srv);
} }
dList_free(servers); servers.clear();
} }
static void Http_fd_map_remove_all(void) static void Http_fd_map_remove_all(void)