dovecot-2.1: auth: Use linked list instead of array for storing ...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jan 9 16:35:34 EET 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/fd8fc3b7615e
changeset: 13911:fd8fc3b7615e
user: Timo Sirainen <tss at iki.fi>
date: Mon Jan 09 16:29:37 2012 +0200
description:
auth: Use linked list instead of array for storing list of auth connections.
With arrays the removal was slower than necessary.
diffstat:
src/auth/auth-client-connection.c | 50 ++++++++++++--------------------------
src/auth/auth-client-connection.h | 4 +-
src/auth/auth-master-connection.c | 38 +++++++++--------------------
src/auth/auth-master-connection.h | 7 +---
src/auth/main.c | 4 +-
5 files changed, 34 insertions(+), 69 deletions(-)
diffs (253 lines):
diff -r 5173218ff7fe -r fd8fc3b7615e src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c Sat Jan 07 20:28:42 2012 +0200
+++ b/src/auth/auth-client-connection.c Mon Jan 09 16:29:37 2012 +0200
@@ -1,13 +1,13 @@
/* Copyright (c) 2002-2011 Dovecot authors, see the included COPYING file */
#include "auth-common.h"
-#include "array.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "network.h"
#include "hex-binary.h"
#include "hostpid.h"
+#include "llist.h"
#include "str.h"
#include "str-sanitize.h"
#include "randgen.h"
@@ -24,12 +24,12 @@
#define OUTBUF_THROTTLE_SIZE (1024*50)
-static ARRAY_DEFINE(auth_client_connections, struct auth_client_connection *);
-
static void auth_client_disconnected(struct auth_client_connection **_conn);
static void auth_client_connection_unref(struct auth_client_connection **_conn);
static void auth_client_input(struct auth_client_connection *conn);
+static struct auth_client_connection *auth_client_connections;
+
static const char *reply_line_hide_pass(const char *line)
{
const char *p, *p2;
@@ -304,7 +304,7 @@
o_stream_set_flush_callback(conn->output, auth_client_output, conn);
conn->io = io_add(fd, IO_READ, auth_client_input, conn);
- array_append(&auth_client_connections, &conn, 1);
+ DLLIST_PREPEND(&auth_client_connections, conn);
str = t_str_new(128);
str_printfa(str, "VERSION\t%u\t%u\n%sSPID\t%s\nCUID\t%u\nCOOKIE\t",
@@ -323,21 +323,12 @@
void auth_client_connection_destroy(struct auth_client_connection **_conn)
{
struct auth_client_connection *conn = *_conn;
- struct auth_client_connection *const *clients;
- unsigned int idx;
*_conn = NULL;
if (conn->fd == -1)
return;
- array_foreach(&auth_client_connections, clients) {
- if (*clients == conn) {
- idx = array_foreach_idx(&auth_client_connections,
- clients);
- array_delete(&auth_client_connections, idx, 1);
- break;
- }
- }
+ DLLIST_REMOVE(&auth_client_connections, conn);
i_stream_close(conn->input);
o_stream_close(conn->output);
@@ -398,30 +389,21 @@
struct auth_client_connection *
auth_client_connection_lookup(unsigned int pid)
{
- struct auth_client_connection *const *clients;
+ struct auth_client_connection *conn;
- array_foreach(&auth_client_connections, clients) {
- struct auth_client_connection *client = *clients;
-
- if (client->pid == pid)
- return client;
+ for (conn = auth_client_connections; conn != NULL; conn = conn->next) {
+ if (conn->pid == pid)
+ return conn;
}
-
return NULL;
}
-void auth_client_connections_init(void)
+void auth_client_connections_destroy_all(void)
{
- i_array_init(&auth_client_connections, 16);
+ struct auth_client_connection *conn;
+
+ while (auth_client_connections != NULL) {
+ conn = auth_client_connections;
+ auth_client_connection_destroy(&conn);
+ }
}
-
-void auth_client_connections_deinit(void)
-{
- struct auth_client_connection **clients;
- unsigned int i, count;
-
- clients = array_get_modifiable(&auth_client_connections, &count);
- for (i = count; i > 0; i--)
- auth_client_connection_destroy(&clients[i-1]);
- array_free(&auth_client_connections);
-}
diff -r 5173218ff7fe -r fd8fc3b7615e src/auth/auth-client-connection.h
--- a/src/auth/auth-client-connection.h Sat Jan 07 20:28:42 2012 +0200
+++ b/src/auth/auth-client-connection.h Mon Jan 09 16:29:37 2012 +0200
@@ -4,6 +4,7 @@
#include "master-auth.h"
struct auth_client_connection {
+ struct auth_client_connection *prev, *next;
struct auth *auth;
int refcount;
@@ -28,7 +29,6 @@
struct auth_client_connection *
auth_client_connection_lookup(unsigned int pid);
-void auth_client_connections_init(void);
-void auth_client_connections_deinit(void);
+void auth_client_connections_destroy_all(void);
#endif
diff -r 5173218ff7fe -r fd8fc3b7615e src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c Sat Jan 07 20:28:42 2012 +0200
+++ b/src/auth/auth-master-connection.c Mon Jan 09 16:29:37 2012 +0200
@@ -1,8 +1,9 @@
/* Copyright (c) 2002-2011 Dovecot authors, see the included COPYING file */
#include "auth-common.h"
-#include "array.h"
+#include "buffer.h"
#include "hash.h"
+#include "llist.h"
#include "str.h"
#include "strescape.h"
#include "str-sanitize.h"
@@ -41,7 +42,7 @@
static void master_input(struct auth_master_connection *conn);
-ARRAY_TYPE(auth_master_connections) auth_master_connections;
+static struct auth_master_connection *auth_master_connections;
static const char *
auth_master_reply_hide_passwords(struct auth_master_connection *conn,
@@ -678,7 +679,7 @@
AUTH_MASTER_PROTOCOL_MINOR_VERSION,
my_pid);
(void)o_stream_send_str(conn->output, line);
- array_append(&auth_master_connections, &conn, 1);
+ DLLIST_PREPEND(&auth_master_connections, conn);
if (auth_master_connection_set_permissions(conn, socket_st) < 0) {
auth_master_connection_destroy(&conn);
@@ -690,22 +691,13 @@
void auth_master_connection_destroy(struct auth_master_connection **_conn)
{
struct auth_master_connection *conn = *_conn;
- struct auth_master_connection *const *masters;
- unsigned int idx;
*_conn = NULL;
if (conn->destroyed)
return;
conn->destroyed = TRUE;
- array_foreach(&auth_master_connections, masters) {
- if (*masters == conn) {
- idx = array_foreach_idx(&auth_master_connections,
- masters);
- array_delete(&auth_master_connections, idx, 1);
- break;
- }
- }
+ DLLIST_REMOVE(&auth_master_connections, conn);
if (conn->input != NULL)
i_stream_close(conn->input);
@@ -749,18 +741,12 @@
i_free(conn);
}
-void auth_master_connections_init(void)
+void auth_master_connections_destroy_all(void)
{
- i_array_init(&auth_master_connections, 16);
+ struct auth_master_connection *conn;
+
+ while (auth_master_connections != NULL) {
+ conn = auth_master_connections;
+ auth_master_connection_destroy(&conn);
+ }
}
-
-void auth_master_connections_deinit(void)
-{
- struct auth_master_connection **masters;
- unsigned int i, count;
-
- masters = array_get_modifiable(&auth_master_connections, &count);
- for (i = count; i > 0; i--)
- auth_master_connection_destroy(&masters[i-1]);
- array_free(&auth_master_connections);
-}
diff -r 5173218ff7fe -r fd8fc3b7615e src/auth/auth-master-connection.h
--- a/src/auth/auth-master-connection.h Sat Jan 07 20:28:42 2012 +0200
+++ b/src/auth/auth-master-connection.h Mon Jan 09 16:29:37 2012 +0200
@@ -5,6 +5,7 @@
struct auth_stream_reply;
struct auth_master_connection {
+ struct auth_master_connection *prev, *next;
struct auth *auth;
int refcount;
@@ -23,9 +24,6 @@
unsigned int destroyed:1;
unsigned int userdb_only:1;
};
-ARRAY_DEFINE_TYPE(auth_master_connections, struct auth_master_connection *);
-
-extern ARRAY_TYPE(auth_master_connections) auth_master_connections;
struct auth_master_connection *
auth_master_connection_create(struct auth *auth, int fd,
@@ -39,7 +37,6 @@
void auth_master_request_callback(struct auth_stream_reply *reply,
void *context);
-void auth_master_connections_init(void);
-void auth_master_connections_deinit(void);
+void auth_master_connections_destroy_all(void);
#endif
diff -r 5173218ff7fe -r fd8fc3b7615e src/auth/main.c
--- a/src/auth/main.c Sat Jan 07 20:28:42 2012 +0200
+++ b/src/auth/main.c Mon Jan 09 16:29:37 2012 +0200
@@ -261,8 +261,8 @@
/* there are no more auth requests */
auths_free();
- auth_client_connections_deinit();
- auth_master_connections_deinit();
+ auth_client_connections_destroy_all();
+ auth_master_connections_destroy_all();
if (auth_worker_client != NULL)
auth_worker_client_destroy(&auth_worker_client);
More information about the dovecot-cvs
mailing list