#include "str.h"
#include "hostpid.h"
#include "net.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "time-util.h"
return str_c(str);
}
-static const char *client_get_disconnect_reason(struct client *client)
-{
- errno = client->input->stream_errno != 0 ?
- client->input->stream_errno :
- client->output->stream_errno;
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- return t_strdup_printf("Connection closed: %s",
- client->input->stream_errno != 0 ?
- i_stream_get_error(client->input) :
- o_stream_get_error(client->output));
-}
-
void client_destroy(struct client *client, const char *reason)
{
client->v.destroy(client, reason);
if (!client->disconnected) {
client->disconnected = TRUE;
- if (reason == NULL)
- reason = client_get_disconnect_reason(client);
+ if (reason == NULL) {
+ reason = io_stream_get_disconnect_reason(client->input,
+ client->output);
+ }
i_info("%s %s", reason, client_stats(client));
}
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
+#include "iostream.h"
#include "net.h"
#include "strescape.h"
#include "llist.h"
const char *connection_disconnect_reason(struct connection *conn)
{
- const char *errstr;
-
- if (conn->input != NULL && conn->input->stream_errno != 0) {
- errno = conn->input->stream_errno;
- errstr = i_stream_get_error(conn->input);
- } else if (conn->output != NULL && conn->output->stream_errno != 0) {
- errno = conn->output->stream_errno;
- errstr = o_stream_get_error(conn->output);
- } else {
- errno = 0;
- errstr = "";
- }
-
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- else
- return t_strdup_printf("Connection closed: %s", errstr);
+ return io_stream_get_disconnect_reason(conn->input, conn->output);
}
void connection_switch_ioloop(struct connection *conn)
#include "base64.h"
#include "str.h"
#include "llist.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "hostpid.h"
err);
}
}
- errno = client->input->stream_errno != 0 ?
- client->input->stream_errno :
- client->output->stream_errno;
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- return t_strdup_printf("Connection closed: %s",
- client->input->stream_errno != 0 ?
- i_stream_get_error(client->input) :
- o_stream_get_error(client->output));
+ return io_stream_get_disconnect_reason(client->input, client->output);
}
+
void client_disconnect(struct client *client, const char *prefix,
const char *reason)
{
#include "hostpid.h"
#include "login-common.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "str.h"
client_auth_failed(client);
}
-static const char *get_disconnect_reason(struct istream *input)
-{
- errno = input->stream_errno;
- return errno == 0 || errno == EPIPE ? "Connection closed" :
- t_strdup_printf("Connection closed: %m");
-}
-
static void proxy_input(struct client *client)
{
struct istream *input;
"(state=%u, duration=%us)%s",
login_proxy_get_host(client->login_proxy),
login_proxy_get_port(client->login_proxy),
- get_disconnect_reason(input),
+ io_stream_get_disconnect_reason(input, NULL),
client->proxy_state, duration,
line == NULL ? "" : t_strdup_printf(
" - BUG: line not read: %s", line)));
#include "array.h"
#include "ioloop.h"
#include "net.h"
+#include "iostream.h"
#include "istream.h"
#include "ostream.h"
#include "crc32.h"
return str_c(str);
}
-static const char *client_get_disconnect_reason(struct client *client)
-{
- errno = client->input->stream_errno != 0 ?
- client->input->stream_errno :
- client->output->stream_errno;
- if (errno == 0 || errno == EPIPE)
- return "Connection closed";
- return t_strdup_printf("Connection closed: %s",
- client->input->stream_errno != 0 ?
- i_stream_get_error(client->input) :
- o_stream_get_error(client->output));
-}
void client_destroy(struct client *client, const char *reason)
{
client->v.destroy(client, reason);
(void)client_update_mails(client);
if (!client->disconnected) {
- if (reason == NULL)
- reason = client_get_disconnect_reason(client);
+ if (reason == NULL) {
+ reason = io_stream_get_disconnect_reason(client->input,
+ client->output);
+ }
i_info("%s %s", reason, client_stats(client));
}