Clients list in file handler is now a vector.
This commit is contained in:
+7
-12
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user