dovecot: Replaced clients hash with a linked list.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Jan 6 02:18:56 EET 2008
details: http://hg.dovecot.org/dovecot/rev/8c6a7af67e8c
changeset: 7119:8c6a7af67e8c
user: Timo Sirainen <tss at iki.fi>
date: Sun Jan 06 02:18:51 2008 +0200
description:
Replaced clients hash with a linked list.
diffstat:
2 files changed, 26 insertions(+), 35 deletions(-)
src/login-common/login-proxy.c | 34 +++++++++++++---------------------
src/login-common/ssl-proxy-openssl.c | 27 +++++++++++++--------------
diffs (168 lines):
diff -r b626d8975193 -r 8c6a7af67e8c src/login-common/login-proxy.c
--- a/src/login-common/login-proxy.c Sun Jan 06 02:18:20 2008 +0200
+++ b/src/login-common/login-proxy.c Sun Jan 06 02:18:51 2008 +0200
@@ -4,7 +4,7 @@
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
-#include "hash.h"
+#include "llist.h"
#include "str-sanitize.h"
#include "client-common.h"
#include "login-proxy.h"
@@ -13,6 +13,8 @@
#define OUTBUF_THRESHOLD 1024
struct login_proxy {
+ struct login_proxy *prev, *next;
+
int client_fd, server_fd;
struct io *client_io, *server_io;
struct istream *server_input;
@@ -28,7 +30,8 @@ struct login_proxy {
unsigned int destroying:1;
};
-static struct hash_table *login_proxies;
+static struct login_proxy *login_proxies = NULL;
+static unsigned int login_proxy_count = 0;
static void server_input(struct login_proxy *proxy)
{
@@ -186,7 +189,8 @@ void login_proxy_free(struct login_proxy
if (proxy->client_fd != -1) {
/* detached proxy */
main_unref();
- hash_remove(login_proxies, proxy);
+ DLLIST_REMOVE(&login_proxies, proxy);
+ login_proxy_count--;
ipstr = net_ip2addr(&proxy->ip);
i_info("proxy(%s): disconnecting %s",
@@ -248,7 +252,7 @@ unsigned int login_proxy_get_port(struct
unsigned int login_proxy_get_count(void)
{
- return login_proxies == NULL ? 0 : hash_count(login_proxies);
+ return login_proxy_count;
}
void login_proxy_detach(struct login_proxy *proxy, struct istream *client_input,
@@ -284,25 +288,13 @@ void login_proxy_detach(struct login_pro
proxy->callback = NULL;
proxy->context = NULL;
- if (login_proxies == NULL) {
- login_proxies = hash_create(system_pool, system_pool,
- 0, NULL, NULL);
- }
- hash_insert(login_proxies, proxy, proxy);
+ login_proxy_count++;
+ DLLIST_PREPEND(&login_proxies, proxy);
main_ref();
}
void login_proxy_deinit(void)
{
- struct hash_iterate_context *iter;
- void *key, *value;
-
- if (login_proxies == NULL)
- return;
-
- iter = hash_iterate_init(login_proxies);
- while (hash_iterate(iter, &key, &value))
- login_proxy_free(value);
- hash_iterate_deinit(&iter);
- hash_destroy(&login_proxies);
-}
+ while (login_proxies != NULL)
+ login_proxy_free(login_proxies);
+}
diff -r b626d8975193 -r 8c6a7af67e8c src/login-common/ssl-proxy-openssl.c
--- a/src/login-common/ssl-proxy-openssl.c Sun Jan 06 02:18:20 2008 +0200
+++ b/src/login-common/ssl-proxy-openssl.c Sun Jan 06 02:18:51 2008 +0200
@@ -6,7 +6,7 @@
#include "network.h"
#include "ostream.h"
#include "read-full.h"
-#include "hash.h"
+#include "llist.h"
#include "ssl-proxy.h"
#include <fcntl.h>
@@ -35,6 +35,7 @@ enum ssl_io_action {
struct ssl_proxy {
int refcount;
+ struct ssl_proxy *prev, *next;
SSL *ssl;
struct ip_addr ip;
@@ -64,7 +65,8 @@ struct ssl_parameters {
static int extdata_index;
static SSL_CTX *ssl_ctx;
-static struct hash_table *ssl_proxies;
+static unsigned int ssl_proxy_count;
+static struct ssl_proxy *ssl_proxies;
static struct ssl_parameters ssl_params;
static int ssl_username_nid;
@@ -495,7 +497,8 @@ int ssl_proxy_new(int fd, struct ip_addr
proxy->ip = *ip;
SSL_set_ex_data(ssl, extdata_index, proxy);
- hash_insert(ssl_proxies, proxy, proxy);
+ ssl_proxy_count++;
+ DLLIST_PREPEND(&ssl_proxies, proxy);
ssl_step(proxy);
main_ref();
@@ -560,7 +563,8 @@ static void ssl_proxy_destroy(struct ssl
return;
proxy->destroyed = TRUE;
- hash_remove(ssl_proxies, proxy);
+ ssl_proxy_count--;
+ DLLIST_REMOVE(&ssl_proxies, proxy);
if (proxy->io_ssl_read != NULL)
io_remove(&proxy->io_ssl_read);
@@ -661,7 +665,7 @@ pem_password_callback(char *buf, int siz
unsigned int ssl_proxy_get_count(void)
{
- return ssl_proxies == NULL ? 0 : hash_count(ssl_proxies);
+ return ssl_proxy_count;
}
static void *ssl_clean_malloc(size_t size)
@@ -778,23 +782,18 @@ void ssl_proxy_init(void)
initialized though. */
(void)RAND_bytes(&buf, 1);
- ssl_proxies = hash_create(system_pool, system_pool, 0, NULL, NULL);
+ ssl_proxy_count = 0;
+ ssl_proxies = NULL;
ssl_initialized = TRUE;
}
void ssl_proxy_deinit(void)
{
- struct hash_iterate_context *iter;
- void *key, *value;
-
if (!ssl_initialized)
return;
- iter = hash_iterate_init(ssl_proxies);
- while (hash_iterate(iter, &key, &value))
- ssl_proxy_destroy(value);
- hash_iterate_deinit(&iter);
- hash_destroy(&ssl_proxies);
+ while (ssl_proxies != NULL)
+ ssl_proxy_destroy(ssl_proxies);
ssl_free_parameters(&ssl_params);
SSL_CTX_free(ssl_ctx);
More information about the dovecot-cvs
mailing list