dovecot-2.2: dsync: Renamed "io" slave to "stream".
dovecot at dovecot.org
dovecot at dovecot.org
Fri Sep 7 16:45:05 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/5943cace4e05
changeset: 15036:5943cace4e05
user: Timo Sirainen <tss at iki.fi>
date: Fri Sep 07 16:19:35 2012 +0300
description:
dsync: Renamed "io" slave to "stream".
diffstat:
src/doveadm/dsync/Makefile.am | 2 +-
src/doveadm/dsync/doveadm-dsync.c | 10 +-
src/doveadm/dsync/dsync-slave-io.c | 1518 -------------------------------
src/doveadm/dsync/dsync-slave-stream.c | 1522 ++++++++++++++++++++++++++++++++
src/doveadm/dsync/dsync-slave.h | 4 +-
5 files changed, 1530 insertions(+), 1526 deletions(-)
diffs (truncated from 3101 to 300 lines):
diff -r 0af20585964d -r 5943cace4e05 src/doveadm/dsync/Makefile.am
--- a/src/doveadm/dsync/Makefile.am Thu Sep 06 01:25:23 2012 +0300
+++ b/src/doveadm/dsync/Makefile.am Fri Sep 07 16:19:35 2012 +0300
@@ -28,7 +28,7 @@
dsync-mailbox-tree-sync.c \
dsync-serializer.c \
dsync-slave.c \
- dsync-slave-io.c \
+ dsync-slave-stream.c \
dsync-slave-pipe.c \
dsync-transaction-log-scan.c
diff -r 0af20585964d -r 5943cace4e05 src/doveadm/dsync/doveadm-dsync.c
--- a/src/doveadm/dsync/doveadm-dsync.c Thu Sep 06 01:25:23 2012 +0300
+++ b/src/doveadm/dsync/doveadm-dsync.c Fri Sep 07 16:19:35 2012 +0300
@@ -334,9 +334,9 @@
else {
string_t *temp_prefix = t_str_new(64);
mail_user_set_get_temp_prefix(temp_prefix, user->set);
- slave = dsync_slave_init_io(ctx->fd_in, ctx->fd_out,
- ctx->remote_name,
- str_c(temp_prefix));
+ slave = dsync_slave_init_stream(ctx->fd_in, ctx->fd_out,
+ ctx->remote_name,
+ str_c(temp_prefix));
}
if (doveadm_debug || doveadm_verbose) {
@@ -520,8 +520,8 @@
temp_prefix = t_str_new(64);
mail_user_set_get_temp_prefix(temp_prefix, user->set);
- slave = dsync_slave_init_io(STDIN_FILENO, STDOUT_FILENO,
- "local", str_c(temp_prefix));
+ slave = dsync_slave_init_stream(STDIN_FILENO, STDOUT_FILENO,
+ "local", str_c(temp_prefix));
brain = dsync_brain_slave_init(user, slave);
io_loop_run(current_ioloop);
diff -r 0af20585964d -r 5943cace4e05 src/doveadm/dsync/dsync-slave-io.c
--- a/src/doveadm/dsync/dsync-slave-io.c Thu Sep 06 01:25:23 2012 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1518 +0,0 @@
-/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */
-
-#include "lib.h"
-#include "array.h"
-#include "fd-set-nonblock.h"
-#include "safe-mkstemp.h"
-#include "ioloop.h"
-#include "istream.h"
-#include "istream-seekable.h"
-#include "istream-dot.h"
-#include "ostream.h"
-#include "str.h"
-#include "strescape.h"
-#include "master-service.h"
-#include "mail-cache.h"
-#include "mail-storage-private.h"
-#include "dsync-serializer.h"
-#include "dsync-deserializer.h"
-#include "dsync-mail.h"
-#include "dsync-mailbox.h"
-#include "dsync-mailbox-state.h"
-#include "dsync-mailbox-tree.h"
-#include "dsync-slave-private.h"
-
-#include <stdlib.h>
-
-#define DSYNC_SLAVE_IO_TIMEOUT_MSECS (60*10*1000)
-#define DSYNC_SLAVE_IO_OUTBUF_THROTTLE_SIZE (1024*128)
-
-#define DSYNC_PROTOCOL_VERSION_MAJOR 3
-#define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t0\n"
-
-enum item_type {
- ITEM_NONE,
-
- ITEM_HANDSHAKE,
- ITEM_MAILBOX_STATE,
- ITEM_MAILBOX_TREE_NODE,
- ITEM_MAILBOX_DELETE,
- ITEM_MAILBOX,
-
- ITEM_MAIL_CHANGE,
- ITEM_MAIL_REQUEST,
- ITEM_MAIL,
-
- ITEM_MAILBOX_CACHE_FIELD,
-
- ITEM_END_OF_LIST
-};
-
-#define END_OF_LIST_LINE "."
-static const struct {
- /* full human readable name of the item */
- const char *name;
- /* unique character identifying the item */
- char chr;
- const char *required_keys;
- const char *optional_keys;
-} items[ITEM_END_OF_LIST+1] = {
- { NULL, '\0', NULL, NULL },
- { .name = "handshake",
- .chr = 'H',
- .optional_keys = "sync_ns_prefix sync_type "
- "guid_requests mails_have_guids"
- },
- { .name = "mailbox_state",
- .chr = 'S',
- .required_keys = "mailbox_guid last_uidvalidity last_common_uid "
- "last_common_modseq"
- },
- { .name = "mailbox_tree_node",
- .chr = 'N',
- .required_keys = "name existence",
- .optional_keys = "mailbox_guid uid_validity "
- "last_renamed_or_created subscribed last_subscription_change"
- },
- { .name = "mailbox_delete",
- .chr = 'D',
- .required_keys = "hierarchy_sep",
- .optional_keys = "mailboxes dirs"
- },
- { .name = "mailbox",
- .chr = 'B',
- .required_keys = "mailbox_guid uid_validity uid_next "
- "messages_count first_recent_uid highest_modseq",
- .optional_keys = "cache_fields"
- },
- { .name = "mail_change",
- .chr = 'C',
- .required_keys = "type uid",
- .optional_keys = "guid hdr_hash modseq save_timestamp "
- "add_flags remove_flags final_flags "
- "keywords_reset keyword_changes"
- },
- { .name = "mail_request",
- .chr = 'R',
- .optional_keys = "guid uid"
- },
- { .name = "mail",
- .chr = 'M',
- .optional_keys = "guid uid pop3_uidl pop3_order received_date stream"
- },
- { .name = "mailbox_cache_field",
- .chr = 'c',
- .required_keys = "name decision",
- .optional_keys = "last_used"
- },
-
- { "end_of_list", '\0', NULL, NULL }
-};
-
-struct dsync_slave_io {
- struct dsync_slave slave;
-
- char *name, *temp_path_prefix;
- int fd_in, fd_out;
- struct istream *input;
- struct ostream *output;
- struct io *io;
- struct timeout *to;
-
- struct dsync_serializer *serializers[ITEM_END_OF_LIST];
- struct dsync_deserializer *deserializers[ITEM_END_OF_LIST];
-
- pool_t ret_pool;
- struct dsync_deserializer_decoder *cur_decoder;
-
- struct istream *mail_output, *mail_input;
- struct dsync_mail *cur_mail;
- char mail_output_last;
-
- unsigned int version_received:1;
- unsigned int handshake_received:1;
- unsigned int has_pending_data:1;
-};
-
-static void dsync_slave_io_stop(struct dsync_slave_io *slave)
-{
- i_stream_close(slave->input);
- o_stream_close(slave->output);
- io_loop_stop(current_ioloop);
-}
-
-static int dsync_slave_io_read_mail_stream(struct dsync_slave_io *slave)
-{
- if (i_stream_read(slave->mail_input) < 0) {
- if (slave->mail_input->stream_errno != 0) {
- errno = slave->mail_input->stream_errno;
- i_error("dsync(%s): read() failed: %m", slave->name);
- dsync_slave_io_stop(slave);
- return -1;
- }
- /* finished reading the mail stream */
- i_assert(slave->mail_input->eof);
- i_stream_seek(slave->mail_input, 0);
- slave->mail_input = NULL;
- return 1;
- }
- i_stream_skip(slave->mail_input,
- i_stream_get_data_size(slave->mail_input));
- return 0;
-}
-
-static void dsync_slave_io_input(struct dsync_slave_io *slave)
-{
- if (slave->mail_input != NULL) {
- if (dsync_slave_io_read_mail_stream(slave) == 0)
- return;
- }
- slave->slave.io_callback(slave->slave.io_context);
-}
-
-static int dsync_slave_io_send_mail_stream(struct dsync_slave_io *slave)
-{
- const unsigned char *data;
- unsigned char add;
- size_t i, size;
- int ret;
-
- while ((ret = i_stream_read_data(slave->mail_output,
- &data, &size, 0)) > 0) {
- add = '\0';
- for (i = 0; i < size; i++) {
- if (data[i] == '\n') {
- if ((i == 0 && slave->mail_output_last != '\r') ||
- (i > 0 && data[i-1] != '\r')) {
- /* missing CR */
- add = '\r';
- break;
- }
- } else if (data[i] == '.' &&
- ((i == 0 && slave->mail_output_last == '\n') ||
- (i > 0 && data[i-1] == '\n'))) {
- /* escape the dot */
- add = '.';
- break;
- }
- }
-
- if (i > 0) {
- o_stream_nsend(slave->output, data, i);
- slave->mail_output_last = data[i-1];
- i_stream_skip(slave->mail_output, i);
- }
-
- if (o_stream_get_buffer_used_size(slave->output) >= 4096) {
- if ((ret = o_stream_flush(slave->output)) < 0) {
- dsync_slave_io_stop(slave);
- return -1;
- }
- if (ret == 0) {
- /* continue later */
- o_stream_set_flush_pending(slave->output, TRUE);
- return 0;
- }
- }
-
- if (add != '\0') {
- o_stream_nsend(slave->output, &add, 1);
- slave->mail_output_last = add;
- }
- }
- i_assert(ret == -1);
-
- if (slave->mail_output->stream_errno != 0) {
- i_error("dsync(%s): read(%s) failed: %m",
- slave->name, i_stream_get_name(slave->mail_output));
- dsync_slave_io_stop(slave);
- return -1;
- }
-
- /* finished sending the stream */
- o_stream_nsend_str(slave->output, "\r\n.\r\n");
- i_stream_unref(&slave->mail_output);
- return 1;
-}
-
-static int dsync_slave_io_output(struct dsync_slave_io *slave)
-{
- struct ostream *output = slave->output;
- int ret;
-
- if ((ret = o_stream_flush(output)) < 0)
- ret = 1;
- else if (slave->mail_output != NULL) {
- if (dsync_slave_io_send_mail_stream(slave) < 0)
- ret = 1;
- }
- timeout_reset(slave->to);
-
- if (!dsync_slave_is_send_queue_full(&slave->slave))
- slave->slave.io_callback(slave->slave.io_context);
- return ret;
-}
-
-static void dsync_slave_io_timeout(struct dsync_slave_io *slave)
-{
More information about the dovecot-cvs
mailing list