connection.h revision a5b64f1abb1cb0a9718d5bf7f0ae808072237259
#ifndef CONNECTION_H
#define CONNECTION_H
#include "net.h"
struct connection;
enum connection_behavior {
};
enum connection_disconnect_reason {
/* not disconnected yet */
/* normal requested disconnection */
/* input buffer full */
/* connection got disconnected */
/* connect() timed out */
/* remote didn't send input */
};
struct connection_vfuncs {
/* For UNIX socket clients this gets called immediately (unless
delayed_unix_client_connected_callback=TRUE) with success=TRUE,
for IP connections it gets called later:
If connect() fails, sets success=FALSE and errno. Streams aren't
initialized in that situation either. destroy() is called after
the callback. */
/* implement one of the input*() methods.
They return 1 = ok, continue. 0 = ok, but stop processing more
lines, -1 = error, disconnect the client. */
};
struct connection_settings {
const char *service_name_in;
const char *service_name_out;
unsigned int major_version, minor_version;
unsigned int client_connect_timeout_msecs;
unsigned int input_idle_timeout_secs;
bool client;
bool dont_send_version;
/* By default when only input_args() is used, or when
connection_input_line_default() is used, empty lines aren't allowed
since it would result in additional args[0] == NULL check. Setting
this to TRUE passes it through instead of logging an error. */
bool allow_empty_args_input;
/* Don't call client_connected() immediately on
connection_client_connect() with UNIX sockets. This is mainly
to make the functionality identical with inet sockets, which may
simplify the calling code. */
/* If connect() to UNIX socket fails with EAGAIN, retry for this many
milliseconds before giving up (0 = try once) */
unsigned int unix_client_connect_msecs;
};
struct connection {
struct connection_list *list;
char *name;
struct timeval last_input_tv;
struct timeval connect_started;
struct timeval connect_finished;
/* for IP client: */
/* received minor version */
unsigned int minor_version;
bool version_received:1;
};
struct connection_list {
struct connection *connections;
unsigned int connections_count;
struct connection_settings set;
struct connection_vfuncs v;
};
struct connection *conn,
/* Returns -1 = disconnected, 0 = nothing new, 1 = something new.
If input_full_behavior is ALLOW, may return also -2 = buffer full. */
/* Verify that VERSION input matches what we expect. */
/* Returns human-readable reason for why connection was disconnected. */
/* Returns human-readable reason for why connection timed out,
e.g. "No input for 10.023 secs". */
struct connection_list *
const struct connection_vfuncs *vfuncs);
#endif