mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 13:51:26 +02:00
REORG/MEDIUM: stream_interface: initialize socket ops from descriptors
This commit is contained in:
parent
1b79bdee26
commit
5c979a9c71
@ -41,6 +41,9 @@ void stream_int_shutw(struct stream_interface *si);
|
|||||||
void stream_int_chk_rcv(struct stream_interface *si);
|
void stream_int_chk_rcv(struct stream_interface *si);
|
||||||
void stream_int_chk_snd(struct stream_interface *si);
|
void stream_int_chk_snd(struct stream_interface *si);
|
||||||
|
|
||||||
|
extern struct sock_ops stream_int_embedded;
|
||||||
|
extern struct sock_ops stream_int_task;
|
||||||
|
|
||||||
struct task *stream_int_register_handler(struct stream_interface *si,
|
struct task *stream_int_register_handler(struct stream_interface *si,
|
||||||
struct si_applet *app);
|
struct si_applet *app);
|
||||||
struct task *stream_int_register_handler_task(struct stream_interface *si,
|
struct task *stream_int_register_handler_task(struct stream_interface *si,
|
||||||
@ -95,6 +98,11 @@ static inline struct server *target_srv(struct target *t)
|
|||||||
return t->ptr.s;
|
return t->ptr.s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void stream_interface_prepare(struct stream_interface *si, const struct sock_ops *ops)
|
||||||
|
{
|
||||||
|
memcpy(&si->sock, ops, sizeof(si->sock));
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _PROTO_STREAM_INTERFACE_H */
|
#endif /* _PROTO_STREAM_INTERFACE_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -39,8 +39,8 @@ void stream_sock_shutr(struct stream_interface *si);
|
|||||||
void stream_sock_shutw(struct stream_interface *si);
|
void stream_sock_shutw(struct stream_interface *si);
|
||||||
void stream_sock_chk_rcv(struct stream_interface *si);
|
void stream_sock_chk_rcv(struct stream_interface *si);
|
||||||
void stream_sock_chk_snd(struct stream_interface *si);
|
void stream_sock_chk_snd(struct stream_interface *si);
|
||||||
void stream_sock_prepare_interface(struct stream_interface *si);
|
|
||||||
|
|
||||||
|
extern struct sock_ops stream_sock;
|
||||||
|
|
||||||
/* This either returns the sockname or the original destination address. Code
|
/* This either returns the sockname or the original destination address. Code
|
||||||
* inspired from Patrick Schaaf's example of nf_getsockname() implementation.
|
* inspired from Patrick Schaaf's example of nf_getsockname() implementation.
|
||||||
|
@ -973,7 +973,7 @@ int connect_server(struct session *s)
|
|||||||
* decide here if we can reuse the connection by comparing the
|
* decide here if we can reuse the connection by comparing the
|
||||||
* session's freshly assigned target with the stream interface's.
|
* session's freshly assigned target with the stream interface's.
|
||||||
*/
|
*/
|
||||||
stream_sock_prepare_interface(s->req->cons);
|
stream_interface_prepare(s->req->cons, &stream_sock);
|
||||||
s->req->cons->connect = tcp_connect_server;
|
s->req->cons->connect = tcp_connect_server;
|
||||||
s->req->cons->get_src = getsockname;
|
s->req->cons->get_src = getsockname;
|
||||||
s->req->cons->get_dst = getpeername;
|
s->req->cons->get_dst = getpeername;
|
||||||
|
@ -1182,7 +1182,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
|
|||||||
if (s->be->options2 & PR_O2_INDEPSTR)
|
if (s->be->options2 & PR_O2_INDEPSTR)
|
||||||
s->si[1].flags |= SI_FL_INDEP_STR;
|
s->si[1].flags |= SI_FL_INDEP_STR;
|
||||||
|
|
||||||
stream_sock_prepare_interface(&s->si[1]);
|
stream_interface_prepare(&s->si[1], &stream_sock);
|
||||||
s->si[1].release = NULL;
|
s->si[1].release = NULL;
|
||||||
|
|
||||||
session_init_srv_conn(s);
|
session_init_srv_conn(s);
|
||||||
|
@ -184,7 +184,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
|||||||
s->si[0].flags = SI_FL_CAP_SPLTCP; /* TCP/TCPv6 splicing possible */
|
s->si[0].flags = SI_FL_CAP_SPLTCP; /* TCP/TCPv6 splicing possible */
|
||||||
|
|
||||||
/* add the various callbacks */
|
/* add the various callbacks */
|
||||||
stream_sock_prepare_interface(&s->si[0]);
|
stream_interface_prepare(&s->si[0], &stream_sock);
|
||||||
|
|
||||||
/* pre-initialize the other side's stream interface to an INIT state. The
|
/* pre-initialize the other side's stream interface to an INIT state. The
|
||||||
* callbacks will be initialized before attempting to connect.
|
* callbacks will be initialized before attempting to connect.
|
||||||
|
@ -32,6 +32,28 @@
|
|||||||
#include <proto/stream_sock.h>
|
#include <proto/stream_sock.h>
|
||||||
#include <proto/task.h>
|
#include <proto/task.h>
|
||||||
|
|
||||||
|
/* socket operations for embedded tasks */
|
||||||
|
struct sock_ops stream_int_embedded = {
|
||||||
|
.update = stream_int_update_embedded,
|
||||||
|
.shutr = stream_int_shutr,
|
||||||
|
.shutw = stream_int_shutw,
|
||||||
|
.chk_rcv = stream_int_chk_rcv,
|
||||||
|
.chk_snd = stream_int_chk_snd,
|
||||||
|
.read = NULL,
|
||||||
|
.write = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
/* socket operations for external tasks */
|
||||||
|
struct sock_ops stream_int_task = {
|
||||||
|
.update = stream_int_update,
|
||||||
|
.shutr = stream_int_shutr,
|
||||||
|
.shutw = stream_int_shutw,
|
||||||
|
.chk_rcv = stream_int_chk_rcv,
|
||||||
|
.chk_snd = stream_int_chk_snd,
|
||||||
|
.read = NULL,
|
||||||
|
.write = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function only has to be called once after a wakeup event in case of
|
* This function only has to be called once after a wakeup event in case of
|
||||||
* suspected timeout. It controls the stream interface timeouts and sets
|
* suspected timeout. It controls the stream interface timeouts and sets
|
||||||
@ -308,13 +330,7 @@ struct task *stream_int_register_handler(struct stream_interface *si, struct si_
|
|||||||
{
|
{
|
||||||
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner);
|
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner);
|
||||||
|
|
||||||
si->sock.update = stream_int_update_embedded;
|
stream_interface_prepare(si, &stream_int_embedded);
|
||||||
si->sock.shutr = stream_int_shutr;
|
|
||||||
si->sock.shutw = stream_int_shutw;
|
|
||||||
si->sock.chk_rcv = stream_int_chk_rcv;
|
|
||||||
si->sock.chk_snd = stream_int_chk_snd;
|
|
||||||
si->sock.read = NULL;
|
|
||||||
si->sock.write = NULL;
|
|
||||||
si->connect = NULL;
|
si->connect = NULL;
|
||||||
set_target_applet(&si->target, app);
|
set_target_applet(&si->target, app);
|
||||||
si->applet.state = 0;
|
si->applet.state = 0;
|
||||||
@ -337,13 +353,7 @@ struct task *stream_int_register_handler_task(struct stream_interface *si,
|
|||||||
|
|
||||||
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", fct, si, si->owner);
|
DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", fct, si, si->owner);
|
||||||
|
|
||||||
si->sock.update = stream_int_update;
|
stream_interface_prepare(si, &stream_int_task);
|
||||||
si->sock.shutr = stream_int_shutr;
|
|
||||||
si->sock.shutw = stream_int_shutw;
|
|
||||||
si->sock.chk_rcv = stream_int_chk_rcv;
|
|
||||||
si->sock.chk_snd = stream_int_chk_snd;
|
|
||||||
si->sock.read = NULL;
|
|
||||||
si->sock.write = NULL;
|
|
||||||
si->connect = NULL;
|
si->connect = NULL;
|
||||||
clear_target(&si->target);
|
clear_target(&si->target);
|
||||||
si->release = NULL;
|
si->release = NULL;
|
||||||
|
@ -1296,19 +1296,16 @@ int stream_sock_accept(int fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* stream sock operations */
|
||||||
/* Prepare a stream interface to be used in socket mode. */
|
struct sock_ops stream_sock = {
|
||||||
void stream_sock_prepare_interface(struct stream_interface *si)
|
.update = stream_sock_data_finish,
|
||||||
{
|
.shutr = stream_sock_shutr,
|
||||||
si->sock.update = stream_sock_data_finish;
|
.shutw = stream_sock_shutw,
|
||||||
si->sock.shutr = stream_sock_shutr;
|
.chk_rcv = stream_sock_chk_rcv,
|
||||||
si->sock.shutw = stream_sock_shutw;
|
.chk_snd = stream_sock_chk_snd,
|
||||||
si->sock.chk_rcv = stream_sock_chk_rcv;
|
.read = stream_sock_read,
|
||||||
si->sock.chk_snd = stream_sock_chk_snd;
|
.write = stream_sock_write,
|
||||||
si->sock.read = stream_sock_read;
|
};
|
||||||
si->sock.write = stream_sock_write;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user