mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-21 03:00:35 +00:00
MINOR: connection: Use a dedicated function to look for a session's connection
The session_get_conn() must now be used to look for an available connection matching a specific target for a given session. This simplifies a bit the connect_server() function.
This commit is contained in:
parent
08016ab82d
commit
fcc3d8a1c0
@ -145,6 +145,35 @@ static inline int session_check_idle_conn(struct session *sess, struct connectio
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Look for an available connection matching the target <target> in the server
|
||||
* list of the session <sess>. It returns a connection if found. Otherwise it
|
||||
* returns NULL.
|
||||
*/
|
||||
static inline struct connection *session_get_conn(struct session *sess, void *target)
|
||||
{
|
||||
struct connection *srv_conn = NULL;
|
||||
struct sess_srv_list *srv_list;
|
||||
|
||||
list_for_each_entry(srv_list, &sess->srv_list, srv_list) {
|
||||
if (srv_list->target == target) {
|
||||
list_for_each_entry(srv_conn, &srv_list->conn_list, session_list) {
|
||||
if (srv_conn->mux && (srv_conn->mux->avail_streams(srv_conn) > 0)) {
|
||||
if (srv_conn->flags & CO_FL_SESS_IDLE) {
|
||||
srv_conn->flags &= ~CO_FL_SESS_IDLE;
|
||||
sess->idle_conns--;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
srv_conn = NULL; /* No available connection found */
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
return srv_conn;
|
||||
}
|
||||
|
||||
#endif /* _HAPROXY_SESSION_H */
|
||||
|
||||
/*
|
||||
|
@ -1197,10 +1197,8 @@ int connect_server(struct stream *s)
|
||||
struct connection *cli_conn = objt_conn(strm_orig(s));
|
||||
struct connection *srv_conn = NULL;
|
||||
struct conn_stream *srv_cs = NULL;
|
||||
struct sess_srv_list *srv_list;
|
||||
struct server *srv;
|
||||
int reuse = 0;
|
||||
int reuse_orphan = 0;
|
||||
int init_mux = 0;
|
||||
int err;
|
||||
int was_unused = 0;
|
||||
@ -1212,21 +1210,9 @@ int connect_server(struct stream *s)
|
||||
si_release_endpoint(&s->si[1]);
|
||||
|
||||
/* first, search for a matching connection in the session's idle conns */
|
||||
list_for_each_entry(srv_list, &s->sess->srv_list, srv_list) {
|
||||
if (srv_list->target == s->target) {
|
||||
list_for_each_entry(srv_conn, &srv_list->conn_list, session_list) {
|
||||
if (conn_xprt_ready(srv_conn) &&
|
||||
srv_conn->mux && (srv_conn->mux->avail_streams(srv_conn) > 0)) {
|
||||
reuse = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reuse)
|
||||
srv_conn = NULL;
|
||||
srv_conn = session_get_conn(s->sess, s->target);
|
||||
if (srv_conn)
|
||||
reuse = 1;
|
||||
|
||||
srv = objt_server(s->target);
|
||||
|
||||
@ -1287,7 +1273,6 @@ int connect_server(struct stream *s)
|
||||
* pick.
|
||||
*/
|
||||
if (srv_conn) {
|
||||
reuse_orphan = 1;
|
||||
reuse = 1;
|
||||
srv_conn->flags &= ~CO_FL_LIST_MASK;
|
||||
}
|
||||
@ -1356,19 +1341,6 @@ int connect_server(struct stream *s)
|
||||
}
|
||||
|
||||
}
|
||||
/* If we're really reusing the connection, remove it from the orphan
|
||||
* list and add it back to the idle list.
|
||||
*/
|
||||
if (reuse) {
|
||||
if (!reuse_orphan) {
|
||||
if (srv_conn->flags & CO_FL_SESS_IDLE) {
|
||||
struct session *sess = srv_conn->owner;
|
||||
|
||||
srv_conn->flags &= ~CO_FL_SESS_IDLE;
|
||||
sess->idle_conns--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (reuse) {
|
||||
if (srv_conn->mux) {
|
||||
|
Loading…
Reference in New Issue
Block a user