/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "connection.h"
#include "llist.h"
#include "istream.h"
#include "ostream.h"
#define INDEXER_CLIENT_PROTOCOL_MINOR_VERSION 0
struct indexer_client {
+ struct connection conn;
struct indexer_client *prev, *next;
int refcount;
struct indexer_queue *queue;
-
- int fd;
- struct istream *input;
- struct ostream *output;
- struct io *io;
-
- bool version_received:1;
- bool handshaked:1;
- bool destroyed:1;
};
struct indexer_client_request {
{
const char *line;
- line = i_stream_next_line(client->input);
+ line = i_stream_next_line(client->conn.input);
if (line == NULL)
return NULL;
indexer_queue_append(client->queue, append, args[1], args[2],
session_id, max_recent_msgs, ctx);
- o_stream_nsend_str(client->output, t_strdup_printf("%u\tOK\n", tag));
+ o_stream_nsend_str(client->conn.output, t_strdup_printf("%u\tOK\n", tag));
return 0;
}
}
indexer_queue_append_optimize(client->queue, args[1], args[2], ctx);
- o_stream_nsend_str(client->output, t_strdup_printf("%u\tOK\n", tag));
+ o_stream_nsend_str(client->conn.output, t_strdup_printf("%u\tOK\n", tag));
return 0;
}
{
const char *line, *const *args, *error;
- switch (i_stream_read(client->input)) {
+ switch (i_stream_read(client->conn.input)) {
case -2:
i_error("BUG: Client connection sent too much data");
indexer_client_destroy(client);
return;
}
- if (!client->version_received) {
- if ((line = i_stream_next_line(client->input)) == NULL)
+ if (!client->conn.version_received) {
+ if ((line = i_stream_next_line(client->conn.input)) == NULL)
return;
if (!version_string_verify(line, "indexer",
indexer_client_destroy(client);
return;
}
- client->version_received = TRUE;
+ client->conn.version_received = TRUE;
}
while ((args = indexer_client_next_line(client)) != NULL) {
struct indexer_client_request *ctx = context;
T_BEGIN {
- o_stream_nsend_str(ctx->client->output,
+ o_stream_nsend_str(ctx->client->conn.output,
t_strdup_printf("%u\t%d\n", ctx->tag, percentage));
} T_END;
if (percentage < 0 || percentage == 100) {
client = i_new(struct indexer_client, 1);
client->refcount = 1;
client->queue = queue;
- client->fd = fd;
- client->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
- client->output = o_stream_create_fd(fd, SIZE_MAX);
- o_stream_set_no_error_handling(client->output, TRUE);
- client->io = io_add(fd, IO_READ, indexer_client_input, client);
+ client->conn.fd_in = fd;
+ client->conn.input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
+ client->conn.output = o_stream_create_fd(fd, SIZE_MAX);
+ o_stream_set_no_error_handling(client->conn.output, TRUE);
+ client->conn.io = io_add(fd, IO_READ, indexer_client_input, client);
DLLIST_PREPEND(&clients, client);
clients_count++;
static void indexer_client_destroy(struct indexer_client *client)
{
- if (client->destroyed)
+ if (client->conn.disconnected)
return;
- client->destroyed = TRUE;
+ client->conn.disconnected = TRUE;
DLLIST_REMOVE(&clients, client);
- io_remove(&client->io);
- i_stream_close(client->input);
- o_stream_close(client->output);
- if (close(client->fd) < 0)
+ io_remove(&client->conn.io);
+ i_stream_close(client->conn.input);
+ o_stream_close(client->conn.output);
+ if (close(client->conn.fd_in) < 0)
i_error("close(client) failed: %m");
- client->fd = -1;
+ client->conn.fd_in = -1;
indexer_client_unref(client);
clients_count--;
if (--client->refcount > 0)
return;
- i_stream_destroy(&client->input);
- o_stream_destroy(&client->output);
+ i_stream_destroy(&client->conn.input);
+ o_stream_destroy(&client->conn.output);
i_free(client);
}