And files ClientInfo is cleanly managed now.
This commit is contained in:
+8
-18
@@ -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 std::vector< ClientInfo * > Clients;
|
||||
static std::vector< std::unique_ptr< ClientInfo > > Clients;
|
||||
/* Set of filedescriptors we're working on */
|
||||
fd_set read_set, write_set;
|
||||
|
||||
@@ -893,9 +893,9 @@ static void termination_handler(int signum)
|
||||
*/
|
||||
static ClientInfo *File_add_client(int sock_fd)
|
||||
{
|
||||
ClientInfo *new_client;
|
||||
auto new_client = std::make_unique< ClientInfo >();
|
||||
auto rv= new_client.get();
|
||||
|
||||
new_client = new ClientInfo;
|
||||
new_client->sh = a_Dpip_dsh_new(sock_fd, sock_fd, 8*1024);
|
||||
new_client->orig_url = NULL;
|
||||
new_client->filename = NULL;
|
||||
@@ -907,18 +907,8 @@ static ClientInfo *File_add_client(int sock_fd)
|
||||
new_client->flags = FILE_READ;
|
||||
new_client->old_style = OLD_STYLE;
|
||||
|
||||
Clients.push_back( new_client );
|
||||
|
||||
return new_client;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove a client from the list.
|
||||
*/
|
||||
static void File_remove_client(ClientInfo *client)
|
||||
{
|
||||
Clients.erase( std::find( begin( Clients ), end( Clients ), client ) );
|
||||
delete client;
|
||||
Clients.push_back( std::move( new_client ) );
|
||||
return rv;
|
||||
}
|
||||
|
||||
ClientInfo::~ClientInfo()
|
||||
@@ -1011,14 +1001,14 @@ static void File_serve_clients(void)
|
||||
int i, f_read, f_write;
|
||||
ClientInfo *client;
|
||||
|
||||
for (i = 0; (client = Clients.at( i ) ); ++i) {
|
||||
for (i = 0; (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)
|
||||
continue;
|
||||
File_serve_client(client, f_write);
|
||||
if (client->flags & (FILE_DONE | FILE_ERR)) {
|
||||
File_remove_client(client);
|
||||
Clients.erase( begin( Clients ) + i );
|
||||
--i;
|
||||
}
|
||||
}
|
||||
@@ -1040,7 +1030,7 @@ 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 = Clients.at( i )); ++i) {
|
||||
for (i = 0; (client = Clients.at( i ).get()); ++i) {
|
||||
if (client->flags & FILE_READ)
|
||||
FD_SET (client->sh->fd_in, &read_set);
|
||||
if (client->flags & FILE_WRITE)
|
||||
|
||||
Reference in New Issue
Block a user