From a93b7621100c39503936260beeecab50b8a367f129e50c9b25f143d82bed10b8 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 10 Jan 2026 03:04:51 -0500 Subject: [PATCH] `Clients` list in file handler is now a vector. --- dpi/file.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/dpi/file.cc b/dpi/file.cc index 191e158..31a401a 100644 --- a/dpi/file.cc +++ b/dpi/file.cc @@ -116,7 +116,7 @@ static const char *File_content_type(const char *filename); static int DPIBYE = 0; static int OLD_STYLE = 0; /* A list for the clients we are serving */ -static Dlist *Clients; +static std::vector< std::unique_ptr< ClientInfo > > Clients; /* Set of filedescriptors we're working on */ fd_set read_set, write_set; @@ -894,9 +894,9 @@ static ClientInfo *File_add_client(int sock_fd) new_client->flags = FILE_READ; new_client->old_style = OLD_STYLE; - dList_append(Clients, new_client.get()); + Clients.push_back( std::move( new_client ) ); - return new_client.release(); + return Clients.back().get(); } /* @@ -904,9 +904,7 @@ static ClientInfo *File_add_client(int sock_fd) */ static void File_remove_client(ClientInfo *client) { - dList_remove(Clients, (void *)client); - - delete client; + Clients.erase( std::find_if( begin( Clients ), end( Clients ), [client] ( const auto &c ) { return client == c.get(); } ) ); } ClientInfo::~ClientInfo() @@ -996,7 +994,7 @@ static void File_serve_clients(void) int i, f_read, f_write; ClientInfo *client; - for (i = 0; (client = reinterpret_cast< ClientInfo * >( dList_nth_data(Clients, i) )); ++i) { + for (i = 0; i < Clients.size() and ( client = Clients.at( i ).get() ); ++i) { f_read = FD_ISSET(client->sh->fd_in, &read_set); f_write = FD_ISSET(client->sh->fd_out, &write_set); if (!f_read && !f_write) @@ -1025,13 +1023,13 @@ static int File_check_fds(uint_t seconds) FD_ZERO (&read_set); FD_ZERO (&write_set); FD_SET (STDIN_FILENO, &read_set); - for (i = 0; (client = reinterpret_cast< ClientInfo * >( dList_nth_data(Clients, i) )); ++i) { + for (i = 0; i < Clients.size() and ( client = Clients.at( i ).get() ); ++i) { if (client->flags & FILE_READ) FD_SET (client->sh->fd_in, &read_set); if (client->flags & FILE_WRITE) FD_SET (client->sh->fd_out, &write_set); } - _MSG("Watching %d fds\n", dList_length(Clients) + 1); + _MSG("Watching %d fds\n", Clients.size() + 1); /* Initialize the timeout data structure. */ timeout.tv_sec = seconds; @@ -1080,9 +1078,6 @@ int main(void) /* Set STDIN socket nonblocking (to ensure accept() never blocks) */ fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK | fcntl(STDIN_FILENO, F_GETFL)); - /* initialize Clients list */ - Clients = dList_new(512); - /* some OSes may need this... */ sin_sz = sizeof(sin);