[dovecot-cvs] dovecot/src/imap-login client.c,1.21,1.22
cras at procontrol.fi
cras at procontrol.fi
Wed Dec 3 02:40:23 EET 2003
Update of /home/cvs/dovecot/src/imap-login
In directory danu:/tmp/cvs-serv14047/imap-login
Modified Files:
client.c
Log Message:
Changed hash_foreach() to iterator.
Index: client.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap-login/client.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- client.c 16 Oct 2003 15:56:20 -0000 1.21
+++ client.c 3 Dec 2003 00:40:21 -0000 1.22
@@ -309,45 +309,40 @@
o_stream_flush(client->output);
}
-static void client_hash_destroy_oldest(void *key, void *value __attr_unused__,
- void *context)
+static void client_destroy_oldest(void)
{
- struct imap_client *client = key;
- struct imap_client *const *destroy_clients;
- buffer_t *destroy_buf = context;
- size_t i, count;
+ struct hash_iterate_context *iter;
+ void *key, *value;
+ struct imap_client *destroy_buf[CLIENT_DESTROY_OLDEST_COUNT];
+ int i;
- destroy_clients = buffer_get_data(destroy_buf, &count);
- count /= sizeof(struct imap_client *);
+ /* find the oldest clients and put them to destroy-buffer */
+ memset(destroy_buf, 0, sizeof(destroy_buf));
- for (i = 0; i < count; i++) {
- if (destroy_clients[i]->created > client->created) {
- buffer_insert(destroy_buf,
- i * sizeof(struct imap_client *),
- &client, sizeof(struct imap_client *));
- break;
+ iter = hash_iterate_init(clients);
+ while (hash_iterate(iter, &key, &value)) {
+ struct imap_client *client = key;
+
+ for (i = 0; i < CLIENT_DESTROY_OLDEST_COUNT; i++) {
+ if (destroy_buf[i] == NULL ||
+ destroy_buf[i]->created > client->created) {
+ /* @UNSAFE */
+ memmove(destroy_buf+i+1, destroy_buf+i,
+ sizeof(destroy_buf) -
+ (i+1) * sizeof(struct imap_client *));
+ destroy_buf[i] = client;
+ break;
+ }
}
}
-}
-
-static void client_destroy_oldest(void)
-{
- struct imap_client *const *destroy_clients;
- buffer_t *destroy_buf;
- size_t i, count;
-
- /* find the oldest clients and put them to destroy-buffer */
- destroy_buf = buffer_create_static_hard(pool_datastack_create(),
- sizeof(struct imap_client *) *
- CLIENT_DESTROY_OLDEST_COUNT);
- hash_foreach(clients, client_hash_destroy_oldest, destroy_buf);
+ hash_iterate_deinit(iter);
/* then kill them */
- destroy_clients = buffer_get_data(destroy_buf, &count);
- count /= sizeof(struct imap_client *);
+ for (i = 0; i < CLIENT_DESTROY_OLDEST_COUNT; i++) {
+ if (destroy_buf[i] == NULL)
+ break;
- for (i = 0; i < count; i++) {
- client_destroy(destroy_clients[i],
+ client_destroy(destroy_buf[i],
"Disconnected: Connection queue full");
}
}
@@ -474,11 +469,8 @@
i_info("%s [%s]", text, addr);
}
-static void client_hash_check_idle(void *key, void *value __attr_unused__,
- void *context __attr_unused__)
+static void client_check_idle(struct imap_client *client)
{
- struct imap_client *client = key;
-
if (ioloop_time - client->last_input >= CLIENT_LOGIN_IDLE_TIMEOUT) {
client_send_line(client, "* BYE Disconnected for inactivity.");
client_destroy(client, "Disconnected: Inactivity");
@@ -487,7 +479,16 @@
static void idle_timeout(void *context __attr_unused__)
{
- hash_foreach(clients, client_hash_check_idle, NULL);
+ struct hash_iterate_context *iter;
+ void *key, *value;
+
+ iter = hash_iterate_init(clients);
+ while (hash_iterate(iter, &key, &value)) {
+ struct imap_client *client = key;
+
+ client_check_idle(client);
+ }
+ hash_iterate_deinit(iter);
}
unsigned int clients_get_count(void)
@@ -495,31 +496,35 @@
return hash_size(clients);
}
-static void client_hash_check_io(void *key, void *value __attr_unused__,
- void *context __attr_unused__)
+void clients_notify_auth_connected(void)
{
- struct imap_client *client = key;
+ struct hash_iterate_context *iter;
+ void *key, *value;
- if (client->input_blocked) {
- client->input_blocked = FALSE;
- client_input(client);
+ iter = hash_iterate_init(clients);
+ while (hash_iterate(iter, &key, &value)) {
+ struct imap_client *client = key;
+
+ if (client->input_blocked) {
+ client->input_blocked = FALSE;
+ client_input(client);
+ }
}
+ hash_iterate_deinit(iter);
}
-void clients_notify_auth_connected(void)
+void clients_destroy_all(void)
{
- hash_foreach(clients, client_hash_check_io, NULL);
-}
+ struct hash_iterate_context *iter;
+ void *key, *value;
-static void client_hash_destroy(void *key, void *value __attr_unused__,
- void *context __attr_unused__)
-{
- client_destroy(key, NULL);
-}
+ iter = hash_iterate_init(clients);
+ while (hash_iterate(iter, &key, &value)) {
+ struct imap_client *client = key;
-void clients_destroy_all(void)
-{
- hash_foreach(clients, client_hash_destroy, NULL);
+ client_destroy(client, NULL);
+ }
+ hash_iterate_deinit(iter);
}
void clients_init(void)
More information about the dovecot-cvs
mailing list