[dovecot-cvs] dovecot/src/auth auth-client-connection.c, 1.7,
1.8 auth-master-connection.c, 1.9, 1.10 password-scheme.c,
1.12, 1.13
cras at dovecot.org
cras at dovecot.org
Sun Aug 15 06:40:32 EEST 2004
Update of /home/cvs/dovecot/src/auth
In directory talvi:/tmp/cvs-serv20173/auth
Modified Files:
auth-client-connection.c auth-master-connection.c
password-scheme.c
Log Message:
We never do blocking reads/writes to network anymore. Changed imap and pop3
processes to use a single I/O loop.
Not much tested yet, and currently LIST/LSUB may eat too much memory and
APPEND eats all CPU.
Index: auth-client-connection.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/auth-client-connection.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- auth-client-connection.c 2 Jul 2004 22:03:37 -0000 1.7
+++ auth-client-connection.c 15 Aug 2004 03:40:30 -0000 1.8
@@ -25,22 +25,19 @@
const void *data,
struct auth_client_connection *conn)
{
+ struct const_iovec iov[2];
ssize_t ret;
- ret = o_stream_send(conn->output, reply, sizeof(*reply));
- if ((size_t)ret == sizeof(*reply)) {
- if (reply->data_size == 0) {
- /* all sent */
- auth_client_connection_unref(conn);
- return;
- }
+ iov[0].iov_base = reply;
+ iov[0].iov_len = sizeof(*reply);
+ iov[1].iov_base = data;
+ iov[2].iov_len = reply->data_size;
- ret = o_stream_send(conn->output, data, reply->data_size);
- if ((size_t)ret == reply->data_size) {
- /* all sent */
- auth_client_connection_unref(conn);
- return;
- }
+ ret = o_stream_sendv(conn->output, iov, 2);
+ if (ret == (ssize_t)(iov[0].iov_len + iov[1].iov_len)) {
+ /* all sent */
+ auth_client_connection_unref(conn);
+ return;
}
if (ret >= 0) {
@@ -188,6 +185,7 @@
static unsigned int connect_uid_counter = 0;
struct auth_client_connection *conn;
struct auth_client_handshake_reply handshake_reply;
+ struct const_iovec iov[2];
pool_t pool;
@@ -214,10 +212,12 @@
handshake_reply = *master->handshake_reply;
handshake_reply.connect_uid = conn->connect_uid;
- if (o_stream_send(conn->output, &handshake_reply,
- sizeof(handshake_reply)) < 0 ||
- o_stream_send(conn->output, master->handshake_reply + 1,
- handshake_reply.data_size) < 0) {
+ iov[0].iov_base = &handshake_reply;
+ iov[0].iov_len = sizeof(handshake_reply);
+ iov[1].iov_base = master->handshake_reply + 1;
+ iov[2].iov_len = handshake_reply.data_size;
+
+ if (o_stream_sendv(conn->output, iov, 2) < 0) {
auth_client_connection_destroy(conn);
conn = NULL;
}
Index: auth-master-connection.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/auth-master-connection.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- auth-master-connection.c 2 Jul 2004 22:03:37 -0000 1.9
+++ auth-master-connection.c 15 Aug 2004 03:40:30 -0000 1.10
@@ -31,6 +31,7 @@
unsigned int tag;
};
+static void master_output(void *context);
static void auth_master_connection_close(struct auth_master_connection *conn);
static int auth_master_connection_unref(struct auth_master_connection *conn);
@@ -94,23 +95,20 @@
ssize_t ret;
reply->tag = tag;
- for (;;) {
- ret = o_stream_send(conn->output, reply, reply_size);
- if (ret < 0) {
- /* master died, kill ourself too */
- auth_master_connection_close(conn);
- break;
- }
- if ((size_t)ret == reply_size)
- break;
+ ret = o_stream_send(conn->output, reply, reply_size);
+ if (ret < 0) {
+ /* master died, kill ourself too */
+ auth_master_connection_close(conn);
+ return;
+ }
+ i_assert((size_t)ret == reply_size);
- /* buffer full, we have to block */
- i_warning("Master transmit buffer full, blocking..");
- if (o_stream_flush(conn->output) < 0) {
- /* transmit error, probably master died */
- auth_master_connection_close(conn);
- break;
+ if (o_stream_get_buffer_used_size(conn->output) >= MAX_OUTBUF_SIZE) {
+ /* buffer full, stop accepting more input */
+ if (conn->io != NULL) {
+ io_remove(conn->io);
+ conn->io = NULL;
}
}
}
@@ -191,6 +189,23 @@
}
}
+static void master_output(void *context)
+{
+ struct auth_master_connection *conn = context;
+ int ret;
+
+ if ((ret = o_stream_flush(conn->output)) < 0) {
+ /* transmit error, probably master died */
+ auth_master_connection_close(conn);
+ return;
+ }
+
+ if (o_stream_get_buffer_used_size(conn->output) <= MAX_OUTBUF_SIZE/2) {
+ /* allow input again */
+ conn->io = io_add(conn->fd, IO_READ, master_input, conn);
+ }
+}
+
static void master_get_handshake_reply(struct auth_master_connection *master)
{
struct mech_module_list *list;
@@ -242,7 +257,8 @@
io_remove(conn->io);
conn->output = o_stream_create_file(fd, default_pool,
- MAX_OUTBUF_SIZE, FALSE);
+ (size_t)-1, FALSE);
+ o_stream_set_flush_callback(conn->output, master_output, conn);
conn->io = io_add(fd, IO_READ, master_input, conn);
conn->fd = fd;
@@ -269,12 +285,13 @@
{
struct auth_master_handshake_reply reply;
- /* just a note to master that we're ok. if we die before,
- master should shutdown itself. */
+ /* just a note to master that we're ok. if we die before, it means
+ we're broken and a simple restart most likely won't help. */
if (conn->output != NULL) {
memset(&reply, 0, sizeof(reply));
reply.server_pid = conn->pid;
- o_stream_send(conn->output, &reply, sizeof(reply));
+ if (o_stream_send(conn->output, &reply, sizeof(reply)) < 0)
+ auth_master_connection_close(conn);
}
}
@@ -290,8 +307,10 @@
o_stream_close(conn->output);
conn->output = NULL;
- io_remove(conn->io);
- conn->io = NULL;
+ if (conn->io != NULL) {
+ io_remove(conn->io);
+ conn->io = NULL;
+ }
}
void auth_master_connection_destroy(struct auth_master_connection *conn)
Index: password-scheme.c
===================================================================
RCS file: /home/cvs/dovecot/src/auth/password-scheme.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- password-scheme.c 30 Jul 2004 01:43:21 -0000 1.12
+++ password-scheme.c 15 Aug 2004 03:40:30 -0000 1.13
@@ -64,7 +64,7 @@
/* stop at next '$' */
p = strchr(p+1, '$');
if (p != NULL)
- *password = t_strdup_until(*password, p);
+ *password = t_strdup_until(*password + 3, p);
return "MD5";
}
}
More information about the dovecot-cvs
mailing list