extern struct mail_storage_callbacks mail_storage_callbacks;
struct imap_module_register imap_module_register = { 0 };
-static struct client *my_client; /* we don't need more than one currently */
+static struct client *imap_clients = NULL;
static void client_idle_timeout(struct client *client)
{
client->anvil_sent = TRUE;
}
- i_assert(my_client == NULL);
- my_client = client;
-
+ DLLIST_PREPEND(&imap_clients, client);
if (hook_client_created != NULL)
hook_client_created(&client);
return client;
i_info("%s %s", reason, client_stats(client));
}
+ DLLIST_REMOVE(&imap_clients, client);
+
i_stream_close(client->input);
o_stream_close(client->output);
pool_unref(&client->command_pool);
i_free(client);
- /* quit the program */
- my_client = NULL;
master_service_client_connection_destroyed(master_service);
}
array_clear(&client->search_updates);
}
-void clients_init(void)
-{
- my_client = NULL;
-}
-
-void clients_deinit(void)
+void clients_destroy_all(void)
{
- if (my_client != NULL) {
- client_send_line(my_client, "* BYE Server shutting down.");
- client_destroy(my_client, "Server shutting down");
+ while (imap_clients != NULL) {
+ client_send_line(imap_clients, "* BYE Server shutting down.");
+ client_destroy(imap_clients, "Server shutting down.");
}
}
};
struct client {
+ struct client *prev, *next;
+
int fd_in, fd_out;
struct io *io;
struct istream *input;
unsigned int *idx_r);
void client_search_updates_free(struct client *client);
-void clients_init(void);
-void clients_deinit(void);
-
void client_command_cancel(struct client_command_context **cmd);
void client_command_free(struct client_command_context **cmd);
bool client_handle_input(struct client *client);
int client_output(struct client *client);
+void clients_destroy_all(void);
+
#endif
log_error_callback, NULL);
}
- clients_init();
-
client = client_create(0, 1, user, set);
client->workarounds = parse_workarounds(set);
{
if (log_io != NULL)
io_remove(&log_io);
- clients_deinit();
+ clients_destroy_all();
}
static void client_connected(const struct master_service_connection *conn)
log_error_callback, NULL);
}
- clients_init();
-
client = client_create(0, 1, user, set);
if (client == NULL)
return FALSE;
{
if (log_io != NULL)
io_remove(&log_io);
- clients_deinit();
+ clients_destroy_all();
}
static void client_connected(const struct master_service_connection *conn)
#include "istream.h"
#include "ostream.h"
#include "str.h"
+#include "llist.h"
#include "hostpid.h"
#include "var-expand.h"
#include "master-service.h"
{ NULL, 0 }
};
-static struct client *my_client; /* we don't need more than one currently */
+static struct client *pop3_clients;
static void client_input(struct client *client);
static int client_output(struct client *client);
client->anvil_sent = TRUE;
}
- i_assert(my_client == NULL);
- my_client = client;
-
+ DLLIST_PREPEND(&pop3_clients, client);
if (hook_client_created != NULL)
hook_client_created(&client);
return client;
client->cmd(client);
i_assert(client->cmd == NULL);
}
+ DLLIST_REMOVE(&pop3_clients, client);
+
if (client->trans != NULL) {
/* client didn't QUIT, but we still want to save any changes
done in this transaction. especially the cached virtual
i_free(client);
- /* quit the program */
- my_client = NULL;
master_service_client_connection_destroyed(master_service);
}
return client->cmd == NULL;
}
-void clients_init(void)
-{
- my_client = NULL;
-}
-
-void clients_deinit(void)
+void clients_destroy_all(void)
{
- if (my_client != NULL) {
- client_send_line(my_client, "-ERR Server shutting down.");
- client_destroy(my_client, "Server shutting down");
+ while (pop3_clients != NULL) {
+ if (pop3_clients->cmd == NULL) {
+ client_send_line(pop3_clients,
+ "-ERR Server shutting down.");
+ }
+ client_destroy(pop3_clients, "Server shutting down.");
}
}
(((client)->messages_count + (CHAR_BIT-1)) / CHAR_BIT)
struct client {
+ struct client *prev, *next;
+
int fd_in, fd_out;
struct io *io;
struct istream *input;
bool client_handle_input(struct client *client);
bool client_update_mails(struct client *client);
-void clients_init(void);
-void clients_deinit(void);
+void clients_destroy_all(void);
#endif