MEDIUM: connection: get rid of CO_FL_CURR_* flags
These ones used to serve as a set of switches between CO_FL_SOCK_* and
CO_FL_XPRT_*, and now that the SOCK layer is gone, they're always a
copy of the last know CO_FL_XPRT_* ones that is resynchronized before
I/O events by calling conn_refresh_polling_flags(), and that are pushed
back to FDs when detecting changes with conn_xprt_polling_changes().
While these functions are not particularly heavy, what they do is
totally redundant by now because the fd_want_*/fd_stop_*() actions
already perform test-and-set operations to decide to create an entry
or not, so they do the exact same thing that is done by
conn_xprt_polling_changes(). As such it is pointless to call that
one, and given that the only reason to keep CO_FL_CURR_* is to detect
changes there, we can now remove them.
Even if this does only save very few cycles, this removes a significant
complexity that has been responsible for many bugs in the past, including
the last one affecting FreeBSD.
All tests look good, and no performance regressions were observed.
diff --git a/src/connection.c b/src/connection.c
index 3337538..bf55f86 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -55,7 +55,6 @@
return;
}
- conn_refresh_polling_flags(conn);
conn->flags |= CO_FL_WILL_UPDATE;
flags = conn->flags & ~CO_FL_ERROR; /* ensure to call the wake handler upon error */
@@ -150,10 +149,9 @@
}
/* Update polling on connection <c>'s file descriptor depending on its current
- * state as reported in the connection's CO_FL_CURR_* flags, reports of EAGAIN
- * in CO_FL_WAIT_*, and the data layer expectations indicated by CO_FL_XPRT_*.
- * The connection flags are updated with the new flags at the end of the
- * operation. Polling is totally disabled if an error was reported.
+ * state as reported in the connection's CO_FL_XPRT_* flags. The connection
+ * flags are updated with the new flags at the end of the operation. Polling
+ * is totally disabled if an error was reported.
*/
void conn_update_xprt_polling(struct connection *c)
{
@@ -163,25 +161,16 @@
return;
/* update read status if needed */
- if (unlikely((f & (CO_FL_CURR_RD_ENA|CO_FL_XPRT_RD_ENA)) == CO_FL_XPRT_RD_ENA)) {
+ if (f & CO_FL_XPRT_RD_ENA)
fd_want_recv(c->handle.fd);
- f |= CO_FL_CURR_RD_ENA;
- }
- else if (unlikely((f & (CO_FL_CURR_RD_ENA|CO_FL_XPRT_RD_ENA)) == CO_FL_CURR_RD_ENA)) {
+ else
fd_stop_recv(c->handle.fd);
- f &= ~CO_FL_CURR_RD_ENA;
- }
/* update write status if needed */
- if (unlikely((f & (CO_FL_CURR_WR_ENA|CO_FL_XPRT_WR_ENA)) == CO_FL_XPRT_WR_ENA)) {
+ if (f & CO_FL_XPRT_WR_ENA)
fd_want_send(c->handle.fd);
- f |= CO_FL_CURR_WR_ENA;
- }
- else if (unlikely((f & (CO_FL_CURR_WR_ENA|CO_FL_XPRT_WR_ENA)) == CO_FL_CURR_WR_ENA)) {
+ else
fd_stop_send(c->handle.fd);
- f &= ~CO_FL_CURR_WR_ENA;
- }
- c->flags = f;
}
/* This is the callback which is set when a connection establishment is pending
diff --git a/src/raw_sock.c b/src/raw_sock.c
index 63c8f6f..91a3593 100644
--- a/src/raw_sock.c
+++ b/src/raw_sock.c
@@ -73,7 +73,6 @@
return 0;
conn->flags &= ~CO_FL_WAIT_ROOM;
- conn_refresh_polling_flags(conn);
errno = 0;
/* Under Linux, if FD_POLL_HUP is set, we have reached the end.
@@ -186,7 +185,6 @@
if (!fd_send_ready(conn->handle.fd))
return 0;
- conn_refresh_polling_flags(conn);
done = 0;
while (pipe->data) {
ret = splice(pipe->cons, NULL, conn->handle.fd, NULL, pipe->data,
@@ -241,7 +239,6 @@
return 0;
conn->flags &= ~CO_FL_WAIT_ROOM;
- conn_refresh_polling_flags(conn);
errno = 0;
if (unlikely(!(fdtab[conn->handle.fd].ev & FD_POLL_IN))) {
@@ -354,7 +351,6 @@
if (!fd_send_ready(conn->handle.fd))
return 0;
- conn_refresh_polling_flags(conn);
done = 0;
/* send the largest possible block. For this we perform only one call
* to send() unless the buffer wraps and we exactly fill the first hunk,
@@ -380,10 +376,8 @@
/* if the system buffer is full, don't insist */
if (ret < try)
break;
- if (!count) {
+ if (!count)
conn_xprt_stop_send(conn);
- conn_refresh_polling_flags(conn);
- }
}
else if (ret == 0 || errno == EAGAIN || errno == ENOTCONN || errno == EINPROGRESS) {
/* nothing written, we need to poll for write first */
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index ff8af23..f2bce21 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -6505,8 +6505,6 @@
ssize_t ret;
size_t try, done = 0;
- conn_refresh_polling_flags(conn);
-
if (!ctx)
goto out_error;
@@ -6631,7 +6629,6 @@
size_t try, done;
done = 0;
- conn_refresh_polling_flags(conn);
if (!ctx)
goto out_error;