From e1f50c4b025330511cca1b5218d2f4537743ea19 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 22 Jan 2014 20:02:06 +0100 Subject: [PATCH] MEDIUM: connection: remove conn_{data,sock}_poll_{recv,send} We simply remove these functions and replace their calls with the appropriate ones : - if we're in the data phase, we can simply report wait on the FD - if we're in the socket phase, we may also have to signal the desire to read/write on the socket because it might not be active yet. --- include/proto/connection.h | 56 +------------------------------------- src/connection.c | 2 +- src/proto_tcp.c | 2 +- src/raw_sock.c | 8 +++--- src/ssl_sock.c | 16 +++++++---- src/stream_interface.c | 2 +- 6 files changed, 18 insertions(+), 68 deletions(-) diff --git a/include/proto/connection.h b/include/proto/connection.h index 9954619be..0bec98e44 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -282,12 +282,6 @@ static inline void __conn_data_stop_recv(struct connection *c) c->flags &= ~CO_FL_DATA_RD_ENA; } -static inline void __conn_data_poll_recv(struct connection *c) -{ - c->flags |= CO_FL_DATA_RD_ENA; - fd_cant_recv(c->t.sock.fd); -} - static inline void __conn_data_want_send(struct connection *c) { c->flags |= CO_FL_DATA_WR_ENA; @@ -298,12 +292,6 @@ static inline void __conn_data_stop_send(struct connection *c) c->flags &= ~CO_FL_DATA_WR_ENA; } -static inline void __conn_data_poll_send(struct connection *c) -{ - c->flags |= CO_FL_DATA_WR_ENA; - fd_cant_send(c->t.sock.fd); -} - static inline void __conn_data_stop_both(struct connection *c) { c->flags &= ~(CO_FL_DATA_WR_ENA | CO_FL_DATA_RD_ENA); @@ -321,12 +309,6 @@ static inline void conn_data_stop_recv(struct connection *c) conn_cond_update_data_polling(c); } -static inline void conn_data_poll_recv(struct connection *c) -{ - __conn_data_poll_recv(c); - conn_cond_update_data_polling(c); -} - static inline void conn_data_want_send(struct connection *c) { __conn_data_want_send(c); @@ -339,12 +321,6 @@ static inline void conn_data_stop_send(struct connection *c) conn_cond_update_data_polling(c); } -static inline void conn_data_poll_send(struct connection *c) -{ - __conn_data_poll_send(c); - conn_cond_update_data_polling(c); -} - static inline void conn_data_stop_both(struct connection *c) { __conn_data_stop_both(c); @@ -366,12 +342,6 @@ static inline void __conn_sock_stop_recv(struct connection *c) c->flags &= ~CO_FL_SOCK_RD_ENA; } -static inline void __conn_sock_poll_recv(struct connection *c) -{ - c->flags |= CO_FL_SOCK_RD_ENA; - fd_cant_recv(c->t.sock.fd); -} - static inline void __conn_sock_want_send(struct connection *c) { c->flags |= CO_FL_SOCK_WR_ENA; @@ -382,12 +352,6 @@ static inline void __conn_sock_stop_send(struct connection *c) c->flags &= ~CO_FL_SOCK_WR_ENA; } -static inline void __conn_sock_poll_send(struct connection *c) -{ - c->flags |= CO_FL_SOCK_WR_ENA; - fd_cant_send(c->t.sock.fd); -} - static inline void __conn_sock_stop_both(struct connection *c) { c->flags &= ~(CO_FL_SOCK_WR_ENA | CO_FL_SOCK_RD_ENA); @@ -405,12 +369,6 @@ static inline void conn_sock_stop_recv(struct connection *c) conn_cond_update_sock_polling(c); } -static inline void conn_sock_poll_recv(struct connection *c) -{ - __conn_sock_poll_recv(c); - conn_cond_update_sock_polling(c); -} - static inline void conn_sock_want_send(struct connection *c) { __conn_sock_want_send(c); @@ -423,12 +381,6 @@ static inline void conn_sock_stop_send(struct connection *c) conn_cond_update_sock_polling(c); } -static inline void conn_sock_poll_send(struct connection *c) -{ - __conn_sock_poll_send(c); - conn_cond_update_sock_polling(c); -} - static inline void conn_sock_stop_both(struct connection *c) { __conn_sock_stop_both(c); @@ -574,8 +526,6 @@ static inline void conn_attach(struct connection *conn, void *owner, const struc */ static inline int conn_drain(struct connection *conn) { - int ret; - if (!conn_ctrl_ready(conn)) return 1; @@ -588,11 +538,7 @@ static inline int conn_drain(struct connection *conn) if (!conn->ctrl->drain) return 0; - ret = conn->ctrl->drain(conn->t.sock.fd); - if (ret < 0) - __conn_data_poll_recv(conn); - - if (ret <= 0) + if (conn->ctrl->drain(conn->t.sock.fd) <= 0) return 0; conn->flags |= CO_FL_SOCK_RD_SH; diff --git a/src/connection.c b/src/connection.c index 0056ec0a6..2538cc521 100644 --- a/src/connection.c +++ b/src/connection.c @@ -261,7 +261,7 @@ int conn_recv_proxy(struct connection *conn, int flag) if (errno == EINTR) continue; if (errno == EAGAIN) { - __conn_sock_poll_recv(conn); + fd_cant_recv(conn->t.sock.fd); return 0; } goto recv_abort; diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 4460bb437..cb1066140 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -657,7 +657,7 @@ int tcp_connect_probe(struct connection *conn) if (connect(fd, (struct sockaddr *)&conn->addr.to, get_addr_len(&conn->addr.to)) < 0) { if (errno == EALREADY || errno == EINPROGRESS) { __conn_sock_stop_recv(conn); - __conn_sock_poll_send(conn); + fd_cant_send(fd); return 0; } diff --git a/src/raw_sock.c b/src/raw_sock.c index 2e3a0cb9a..3d4278146 100644 --- a/src/raw_sock.c +++ b/src/raw_sock.c @@ -145,7 +145,7 @@ int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int co #ifndef ASSUME_SPLICE_WORKS if (splice_detects_close) #endif - __conn_data_poll_recv(conn); /* we know for sure that it's EAGAIN */ + fd_cant_recv(conn->t.sock.fd); /* we know for sure that it's EAGAIN */ break; } else if (errno == ENOSYS || errno == EINVAL || errno == EBADF) { @@ -203,7 +203,7 @@ int raw_sock_from_pipe(struct connection *conn, struct pipe *pipe) if (ret <= 0) { if (ret == 0 || errno == EAGAIN) { - __conn_data_poll_send(conn); + fd_cant_send(conn->t.sock.fd); break; } else if (errno == EINTR) @@ -298,7 +298,7 @@ static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int coun goto read0; } else if (errno == EAGAIN) { - __conn_data_poll_recv(conn); + fd_cant_recv(conn->t.sock.fd); break; } else if (errno != EINTR) { @@ -376,7 +376,7 @@ static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int fl } else if (ret == 0 || errno == EAGAIN || errno == ENOTCONN) { /* nothing written, we need to poll for write first */ - __conn_data_poll_send(conn); + fd_cant_send(conn->t.sock.fd); break; } else if (errno != EINTR) { diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 0cfcca798..d30a8eb88 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -1191,7 +1191,8 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag) if (ret == SSL_ERROR_WANT_WRITE) { /* SSL handshake needs to write, L4 connection may not be ready */ __conn_sock_stop_recv(conn); - __conn_sock_poll_send(conn); + __conn_sock_want_send(conn); + fd_cant_send(conn->t.sock.fd); return 0; } else if (ret == SSL_ERROR_WANT_READ) { @@ -1206,7 +1207,8 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag) if (conn->flags & CO_FL_WAIT_L4_CONN) conn->flags &= ~CO_FL_WAIT_L4_CONN; __conn_sock_stop_send(conn); - __conn_sock_poll_recv(conn); + __conn_sock_want_recv(conn); + fd_cant_recv(conn->t.sock.fd); return 0; } else if (ret == SSL_ERROR_SYSCALL) { @@ -1249,7 +1251,8 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag) if (ret == SSL_ERROR_WANT_WRITE) { /* SSL handshake needs to write, L4 connection may not be ready */ __conn_sock_stop_recv(conn); - __conn_sock_poll_send(conn); + __conn_sock_want_send(conn); + fd_cant_send(conn->t.sock.fd); return 0; } else if (ret == SSL_ERROR_WANT_READ) { @@ -1257,7 +1260,8 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag) if (conn->flags & CO_FL_WAIT_L4_CONN) conn->flags &= ~CO_FL_WAIT_L4_CONN; __conn_sock_stop_send(conn); - __conn_sock_poll_recv(conn); + __conn_sock_want_recv(conn); + fd_cant_recv(conn->t.sock.fd); return 0; } else if (ret == SSL_ERROR_SYSCALL) { @@ -1404,7 +1408,7 @@ static int ssl_sock_to_buf(struct connection *conn, struct buffer *buf, int coun break; } /* we need to poll for retry a read later */ - __conn_data_poll_recv(conn); + fd_cant_recv(conn->t.sock.fd); break; } /* otherwise it's a real error */ @@ -1485,7 +1489,7 @@ static int ssl_sock_from_buf(struct connection *conn, struct buffer *buf, int fl break; } /* we need to poll to retry a write later */ - __conn_data_poll_send(conn); + fd_cant_send(conn->t.sock.fd); break; } else if (ret == SSL_ERROR_WANT_READ) { diff --git a/src/stream_interface.c b/src/stream_interface.c index 063c1731d..6096dd749 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -487,7 +487,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag) out_wait: __conn_sock_stop_recv(conn); - __conn_sock_poll_send(conn); + fd_cant_send(conn->t.sock.fd); return 0; }