CLEANUP: connection: split sock_ops into data_ops, app_cp and si_ops
Some parts of the sock_ops structure were only used by the stream
interface and have been moved into si_ops. Some of them were callbacks
to the stream interface from the connection and have been moved into
app_cp as they're the application seen from the connection (later,
health-checks will need to use them). The rest has moved to data_ops.
Normally at this point the connection could live without knowing about
stream interfaces at all.
diff --git a/include/proto/raw_sock.h b/include/proto/raw_sock.h
index 36d4dec..5edc346 100644
--- a/include/proto/raw_sock.h
+++ b/include/proto/raw_sock.h
@@ -24,7 +24,7 @@
#include <types/stream_interface.h>
-extern struct sock_ops raw_sock;
+extern struct data_ops raw_sock;
#endif /* _PROTO_RAW_SOCK_H */
diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h
index 4f45c12..4bb4aae 100644
--- a/include/proto/stream_interface.h
+++ b/include/proto/stream_interface.h
@@ -36,17 +36,16 @@
void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg);
int conn_si_send_proxy(struct connection *conn, unsigned int flag);
void conn_notify_si(struct connection *conn);
-void stream_int_update_conn(struct stream_interface *si);
int stream_int_shutr(struct stream_interface *si);
int stream_int_shutw(struct stream_interface *si);
-void stream_int_chk_rcv_conn(struct stream_interface *si);
-void stream_int_chk_snd_conn(struct stream_interface *si);
void si_conn_recv_cb(struct connection *conn);
void si_conn_send_cb(struct connection *conn);
void stream_sock_read0(struct stream_interface *si);
-extern struct sock_ops stream_int_embedded;
-extern struct sock_ops stream_int_task;
+extern struct si_ops si_embedded_ops;
+extern struct si_ops si_task_ops;
+extern struct si_ops si_conn_ops;
+extern struct app_cb si_conn_cb;
struct task *stream_int_register_handler(struct stream_interface *si,
struct si_applet *app);
@@ -59,11 +58,6 @@
return si->conn.ctrl;
}
-static inline const struct sock_ops *si_data(struct stream_interface *si)
-{
- return si->conn.data;
-}
-
static inline int si_fd(struct stream_interface *si)
{
return si->conn.t.sock.fd;
@@ -130,13 +124,35 @@
return t->ptr.l;
}
-static inline void stream_interface_prepare(struct stream_interface *si, const struct sock_ops *ops)
+static inline void si_prepare_conn(struct stream_interface *si, const struct protocol *ctrl, const struct data_ops *ops)
{
+ si->ops = &si_conn_ops;
+ si->conn.app_cb = &si_conn_cb;
+ si->conn.ctrl = ctrl;
si->conn.data = ops;
si->conn.data_st = 0;
si->conn.data_ctx = NULL;
}
+static inline void si_prepare_embedded(struct stream_interface *si)
+{
+ si->ops = &si_embedded_ops;
+ si->conn.app_cb = NULL;
+ si->conn.ctrl = NULL;
+ si->conn.data = NULL;
+ si->conn.data_st = 0;
+ si->conn.data_ctx = NULL;
+}
+
+static inline void si_prepare_task(struct stream_interface *si)
+{
+ si->ops = &si_task_ops;
+ si->conn.app_cb = NULL;
+ si->conn.ctrl = NULL;
+ si->conn.data = NULL;
+ si->conn.data_st = 0;
+ si->conn.data_ctx = NULL;
+}
/* Retrieves the source address for the stream interface. */
static inline void si_get_from_addr(struct stream_interface *si)
@@ -187,19 +203,19 @@
/* Calls the data state update on the stream interfaace */
static inline void si_update(struct stream_interface *si)
{
- si_data(si)->update(si);
+ si->ops->update(si);
}
/* Calls chk_rcv on the connection using the data layer */
static inline void si_chk_rcv(struct stream_interface *si)
{
- si_data(si)->chk_rcv(si);
+ si->ops->chk_rcv(si);
}
/* Calls chk_snd on the connection using the data layer */
static inline void si_chk_snd(struct stream_interface *si)
{
- si_data(si)->chk_snd(si);
+ si->ops->chk_snd(si);
}
/* Calls chk_snd on the connection using the ctrl layer */
diff --git a/include/types/connection.h b/include/types/connection.h
index 6d402cf..1714522 100644
--- a/include/types/connection.h
+++ b/include/types/connection.h
@@ -28,8 +28,10 @@
#include <common/config.h>
/* referenced below */
-struct sock_ops;
struct protocol;
+struct connection;
+struct buffer;
+struct pipe;
/* Polling flags that are manipulated by I/O callbacks and handshake callbacks
* indicate what they expect from a file descriptor at each layer. For each
@@ -108,6 +110,29 @@
CO_FL_CURR_WR_POL = CO_FL_WR_POL << 28, /* sending needs to poll first */
};
+
+/* data_ops describes data-layer operations for a connection. They generally
+ * run over a socket-based control layer, but not always.
+ */
+struct data_ops {
+ int (*rcv_buf)(struct connection *conn, struct buffer *buf, int count); /* recv callback */
+ int (*snd_buf)(struct connection *conn, struct buffer *buf, int flags); /* send callback */
+ int (*rcv_pipe)(struct connection *conn, struct pipe *pipe, unsigned int count); /* recv-to-pipe callback */
+ int (*snd_pipe)(struct connection *conn, struct pipe *pipe); /* send-to-pipe callback */
+ void (*shutr)(struct connection *, int); /* shutr function */
+ void (*shutw)(struct connection *, int); /* shutw function */
+ void (*close)(struct connection *); /* close the data channel on the connection */
+};
+
+/* app_cb describes read and write callbacks which are called upon detected I/O
+ * activity at the data layer. These callbacks are supposed to make use of the
+ * data_ops above to exchange data from/to buffers and pipes.
+ */
+struct app_cb {
+ void (*recv)(struct connection *conn); /* application-layer recv callback */
+ void (*send)(struct connection *conn); /* application-layer send callback */
+};
+
/* This structure describes a connection with its methods and data.
* A connection may be performed to proxy or server via a local or remote
* socket, and can also be made to an internal applet. It can support
@@ -116,8 +141,9 @@
* connections, but other methods for applets.
*/
struct connection {
- const struct sock_ops *data; /* operations at the data layer */
- const struct protocol *ctrl; /* operations at the control layer, generally a protocol */
+ const struct data_ops *data; /* operations at the data layer */
+ const struct protocol *ctrl; /* operations at the socket layer */
+ const struct app_cb *app_cb; /* application layer callbacks */
union { /* definitions which depend on connection type */
struct { /*** information used by socket-based connections ***/
int fd; /* file descriptor for a stream driver when known */
diff --git a/include/types/peers.h b/include/types/peers.h
index 9e33d6d..0b1a74c 100644
--- a/include/types/peers.h
+++ b/include/types/peers.h
@@ -74,7 +74,7 @@
time_t last_change;
struct sockaddr_storage addr; /* peer address */
struct protocol *proto; /* peer address protocol */
- struct sock_ops *sock; /* peer socket operations */
+ struct data_ops *data; /* peer socket operations at data layer */
void *sock_init_arg; /* socket operations's opaque init argument if needed */
struct peer *next; /* next peer in the list */
};
diff --git a/include/types/protocols.h b/include/types/protocols.h
index ac52a53..6869644 100644
--- a/include/types/protocols.h
+++ b/include/types/protocols.h
@@ -102,7 +102,7 @@
int options; /* socket options : LI_O_* */
struct licounters *counters; /* statistics counters */
struct protocol *proto; /* protocol this listener belongs to */
- struct sock_ops *sock; /* listener socket operations */
+ struct data_ops *data; /* data-layer operations operations for this socket */
int nbconn; /* current number of connections on this listener */
int maxconn; /* maximum connections allowed on this listener */
unsigned int backlog; /* if set, listen backlog */
diff --git a/include/types/server.h b/include/types/server.h
index 7a405fd..c952885 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -151,8 +151,7 @@
int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */
#endif
struct protocol *proto; /* server address protocol */
- struct sock_ops *sock; /* server socket operations */
- void *sock_init_arg; /* socket operations's opaque init argument if needed */
+ struct data_ops *data; /* data-layer operations */
unsigned down_time; /* total time the server was down */
time_t last_change; /* last time, when the state was changed */
struct timeval check_start; /* last health check start time */
diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h
index 921363f..5985619 100644
--- a/include/types/stream_interface.h
+++ b/include/types/stream_interface.h
@@ -91,12 +91,10 @@
#define SI_FL_CAP_SPLICE (SI_FL_CAP_SPLTCP)
-struct buffer;
struct server;
struct proxy;
struct si_applet;
struct stream_interface;
-struct pipe;
struct target {
int type;
@@ -110,19 +108,11 @@
} ptr;
};
-struct sock_ops {
+/* operations available on a stream-interface */
+struct si_ops {
void (*update)(struct stream_interface *); /* I/O update function */
- void (*shutr)(struct connection *, int); /* shutr function */
- void (*shutw)(struct connection *, int); /* shutw function */
void (*chk_rcv)(struct stream_interface *); /* chk_rcv function */
void (*chk_snd)(struct stream_interface *); /* chk_snd function */
- void (*read)(struct connection *conn); /* read callback after poll() */
- void (*write)(struct connection *conn); /* write callback after poll() */
- void (*close)(struct connection *); /* close the data channel on the connection */
- int (*rcv_buf)(struct connection *conn, struct buffer *buf, int count); /* recv callback */
- int (*snd_buf)(struct connection *conn, struct buffer *buf, int flags); /* send callback */
- int (*rcv_pipe)(struct connection *conn, struct pipe *pipe, unsigned int count); /* recv-to-pipe callback */
- int (*snd_pipe)(struct connection *conn, struct pipe *pipe); /* send-to-pipe callback */
};
/* A stream interface has 3 parts :
@@ -148,6 +138,7 @@
void *err_loc; /* commonly the server, NULL when SI_ET_NONE */
struct connection conn; /* descriptor for a connection */
+ struct si_ops *ops; /* general operations at the stream interface layer */
void (*release)(struct stream_interface *); /* handler to call after the last close() */