]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: fix inconsistency between fd->iocb, proto->accept and accept()
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Apr 2016 09:13:20 +0000 (11:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 14 Apr 2016 09:18:22 +0000 (11:18 +0200)
There's quite some inconsistency in the internal API. listener_accept()
which is the main accept() function returns void but is declared as int
in the include file. It's assigned to proto->accept() for all stream
protocols where an int is expected but the result is never checked (nor
is it documented by the way). This proto->accept() is in turn assigned
to fd->iocb() which is supposed to return an int composed of FD_WAIT_*
flags, but which is never checked either.

So let's fix all this mess :
  - nobody checks accept()'s return
  - nobody checks iocb()'s return
  - nobody sets a return value

=> let's mark all these functions void and keep the current ones intact.

Additionally we now include listener.h from listener.c to ensure we won't
silently hide this incoherency in the future.

Note that this patch could/should be backported to 1.6 and even 1.5 to
simplify debugging sessions.

include/proto/connection.h
include/proto/listener.h
include/proto/proto_udp.h
include/types/fd.h
include/types/protocol.h
src/connection.c
src/listener.c
src/proto_udp.c

index 952f9ea2f54034c90842d34a11b008442b93aee7..f50329c380239cdb7549a334a0ca07f46a2e78c1 100644 (file)
@@ -35,9 +35,9 @@ extern struct pool_head *pool2_connection;
 int init_connection();
 
 /* I/O callback for fd-based connections. It calls the read/write handlers
- * provided by the connection's sock_ops. Returns 0.
+ * provided by the connection's sock_ops.
  */
-int conn_fd_handler(int fd);
+void conn_fd_handler(int fd);
 
 /* receive a PROXY protocol header over a connection */
 int conn_recv_proxy(struct connection *conn, int flag);
index 1473bfda7d5b69b783c591657bc3df6d51b069e8..75bae86d90ddcf46b11962f3788c9b3387248b16 100644 (file)
@@ -105,7 +105,7 @@ void delete_listener(struct listener *listener);
  * to an accept. It tries to accept as many connections as possible, and for each
  * calls the listener's accept handler (generally the frontend's accept handler).
  */
-int listener_accept(int fd);
+void listener_accept(int fd);
 
 /*
  * Registers the bind keyword list <kwl> as a list of valid keywords for next
index c452a10b9bb911cbf8ad94c1aa8df6820f3a718e..d1f0698c63291df944f48434978877603390e6ec 100644 (file)
@@ -22,6 +22,6 @@
 #ifndef _PROTO_PROTO_UDP_H
 #define _PROTO_PROTO_UDP_H
 
-int dgram_fd_handler(int);
+void dgram_fd_handler(int);
 
 #endif // _PROTO_PROTO_UDP_H
index 057d968adbdf0f57fe48121a567edec990f8edd5..8299a0264c1a6f4cf82d28d539354b8cd7ed64c8 100644 (file)
@@ -78,7 +78,7 @@ enum fd_states {
 
 /* info about one given fd */
 struct fdtab {
-       int (*iocb)(int fd);                 /* I/O handler, returns FD_WAIT_* */
+       void (*iocb)(int fd);                /* I/O handler */
        void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
        unsigned int  cache;                 /* position+1 in the FD cache. 0=not in cache. */
        unsigned char state;                 /* FD state for read and write directions (2*3 bits) */
index 74b20e8fa1fa4755be2916b4fb7064874c0faeb2..6a4986ff4a09e2411935602e488081f172637281 100644 (file)
@@ -50,7 +50,7 @@ struct protocol {
        sa_family_t sock_family;                        /* socket family, for sockaddr */
        socklen_t sock_addrlen;                         /* socket address length, used by bind() */
        int l3_addrlen;                                 /* layer3 address length, used by hashes */
-       int (*accept)(int fd);                          /* generic accept function */
+       void (*accept)(int fd);                         /* generic accept function */
        int (*bind)(struct listener *l, char *errmsg, int errlen); /* bind a listener */
        int (*bind_all)(struct protocol *proto, char *errmsg, int errlen); /* bind all unbound listeners */
        int (*unbind_all)(struct protocol *proto);      /* unbind all bound listeners */
index b8be0a106fdf185676c7dd7d4d61d263e9aa0269..330f3efbc995e0b1cf1c24ff063a89fef1c53c91 100644 (file)
@@ -36,15 +36,15 @@ int init_connection()
 }
 
 /* I/O callback for fd-based connections. It calls the read/write handlers
- * provided by the connection's sock_ops, which must be valid. It returns 0.
+ * provided by the connection's sock_ops, which must be valid.
  */
-int conn_fd_handler(int fd)
+void conn_fd_handler(int fd)
 {
        struct connection *conn = fdtab[fd].owner;
        unsigned int flags;
 
        if (unlikely(!conn))
-               return 0;
+               return;
 
        conn_refresh_polling_flags(conn);
        flags = conn->flags & ~CO_FL_ERROR; /* ensure to call the wake handler upon error */
@@ -86,7 +86,7 @@ int conn_fd_handler(int fd)
         * we must not use it anymore and should immediately leave instead.
         */
        if ((conn->flags & CO_FL_INIT_DATA) && conn->data->init(conn) < 0)
-               return 0;
+               return;
 
        /* The data transfer starts here and stops on error and handshakes. Note
         * that we must absolutely test conn->xprt at each step in case it suddenly
@@ -133,7 +133,7 @@ int conn_fd_handler(int fd)
        if ((conn->flags & CO_FL_WAKE_DATA) &&
            ((conn->flags ^ flags) & CO_FL_CONN_STATE) &&
            conn->data->wake(conn) < 0)
-               return 0;
+               return;
 
        /* Last check, verify if the connection just established */
        if (unlikely(!(conn->flags & (CO_FL_WAIT_L4_CONN | CO_FL_WAIT_L6_CONN | CO_FL_CONNECTED))))
@@ -144,7 +144,7 @@ int conn_fd_handler(int fd)
 
        /* commit polling changes */
        conn_cond_update_polling(conn);
-       return 0;
+       return;
 }
 
 /* Update polling on connection <c>'s file descriptor depending on its current
index 5abeb806f688d401bf9cb9589b778d4433ceeebc..566b34082ac85119d246771e86254330f4adcdf1 100644 (file)
@@ -32,6 +32,7 @@
 #include <proto/fd.h>
 #include <proto/freq_ctr.h>
 #include <proto/log.h>
+#include <proto/listener.h>
 #include <proto/sample.h>
 #include <proto/stream.h>
 #include <proto/task.h>
index 0e361d928bb8d6dacdea4634243bfecbef5d16e3..c4434d78eaa6aa627890f59918d72a41a674aff2 100644 (file)
 #include <proto/fd.h>
 
 /* datagram handler callback */
-int dgram_fd_handler(int fd)
+void dgram_fd_handler(int fd)
 {
        struct dgram_conn *dgram = fdtab[fd].owner;
 
        if (unlikely(!dgram))
-               return 0;
+               return;
 
        if (fd_recv_ready(fd))
                dgram->data->recv(dgram);
        else if (fd_send_ready(fd))
                dgram->data->send(dgram);
 
-       return 0;
+       return;
 }