]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[CLEANUP] remove ifdef MSG_NOSIGNAL and define it instead
authorWilly Tarreau <w@1wt.eu>
Wed, 19 Aug 2009 09:22:33 +0000 (11:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 3 Oct 2009 17:12:12 +0000 (19:12 +0200)
ifdefs are really annoying in the code. Define MSG_NOSIGNAL to zero
when undefined and remove associated ifdefs.

(cherry picked from commit d6d06909dae55bd594f5a9d6bf54dad04eae382f)

include/common/compat.h
src/checks.c
src/haproxy.c
src/log.c
src/stream_sock.c

index 8d406e5c469832555b5bcc1909e55b0a178c8631..dec5d7d43026206e6e86a838d3048c657204d42c 100644 (file)
 #define SHUT_WR                1
 #endif
 
+/* only Linux defines it */
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL   0
+#endif
+
 /* AIX does not define MSG_DONTWAIT. We'll define it to zero, and test it
  * wherever appropriate.
  */
index b4e985702e242269a13cc41101486040f725b9c2..26d4706bf686ca2ae390485b3d32ab782122ee7b 100644 (file)
@@ -358,11 +358,7 @@ static int event_srv_chk_w(int fd)
                                memcpy(s->proxy->check_req + 11, &gmt_time, 4);
                        }
 
-#ifndef MSG_NOSIGNAL
-                       ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT);
-#else
                        ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT | MSG_NOSIGNAL);
-#endif
                        if (ret == s->proxy->check_len) {
                                /* we allow up to <timeout.check> if nonzero for a responce */
                                if (s->proxy->timeout.check)
@@ -454,15 +450,11 @@ static int event_srv_chk_r(int fd)
                goto out_wakeup;
        }
 
-#ifndef MSG_NOSIGNAL
-       len = recv(fd, trash, sizeof(trash), 0);
-#else
        /* Warning! Linux returns EAGAIN on SO_ERROR if data are still available
         * but the connection was closed on the remote end. Fortunately, recv still
         * works correctly and we don't need to do the getsockopt() on linux.
         */
        len = recv(fd, trash, sizeof(trash), MSG_NOSIGNAL);
-#endif
        if (unlikely(len < 0 && errno == EAGAIN)) {
                /* we want some polling to happen first */
                fdtab[fd].ev &= ~FD_POLL_IN;
index 607ff155f4321aafe02c52ceb6bdde4767e352d4..240b8ad8b206292796e6cafb6ee5e61c7637df84 100644 (file)
@@ -933,7 +933,7 @@ int main(int argc, char **argv)
        /* on very high loads, a sigpipe sometimes happen just between the
         * getsockopt() which tells "it's OK to write", and the following write :-(
         */
-#if !defined(MSG_NOSIGNAL) || defined(CONFIG_HAP_LINUX_SPLICE)
+#if !MSG_NOSIGNAL || defined(CONFIG_HAP_LINUX_SPLICE)
        signal(SIGPIPE, SIG_IGN);
 #endif
 
index 8d71eae3f5381e2b41163a049c0efd1facf739b0..b323d7e89a9289143076195bf7b84e4449f5a89c 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -23,6 +23,7 @@
 #include <sys/time.h>
 
 #include <common/config.h>
+#include <common/compat.h>
 #include <common/standard.h>
 #include <common/time.h>
 
 
 #include <proto/log.h>
 
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL   (0)
-#endif /* !MSG_NOSIGNAL */
-
 const char *log_facilities[NB_LOG_FACILITIES] = {
        "kern", "user", "mail", "daemon",
        "auth", "syslog", "lpr", "news",
index bd8d271c113109417d4dd91e0ed890667f9b5315..0ee339c0c0da4be34a33ad0019652f814743d676 100644 (file)
@@ -301,8 +301,9 @@ int stream_sock_read(int fd) {
                /*
                 * 2. read the largest possible block
                 */
-#ifndef MSG_NOSIGNAL
-               {
+               if (MSG_NOSIGNAL) {
+                       ret = recv(fd, b->r, max, MSG_NOSIGNAL);
+               } else {
                        int skerr;
                        socklen_t lskerr = sizeof(skerr);
 
@@ -312,9 +313,7 @@ int stream_sock_read(int fd) {
                        else
                                ret = recv(fd, b->r, max, 0);
                }
-#else
-               ret = recv(fd, b->r, max, MSG_NOSIGNAL);
-#endif
+
                if (ret > 0) {
                        b->r += ret;
                        b->l += ret;
@@ -574,8 +573,9 @@ static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b)
                if (max > b->send_max)
                        max = b->send_max;
 
-#ifndef MSG_NOSIGNAL
-               {
+               if (MSG_NOSIGNAL) {
+                       ret = send(si->fd, b->w, max, MSG_DONTWAIT | MSG_NOSIGNAL);
+               } else {
                        int skerr;
                        socklen_t lskerr = sizeof(skerr);
 
@@ -585,9 +585,6 @@ static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b)
                        else
                                ret = send(si->fd, b->w, max, MSG_DONTWAIT);
                }
-#else
-               ret = send(si->fd, b->w, max, MSG_DONTWAIT | MSG_NOSIGNAL);
-#endif
 
                if (ret > 0) {
                        if (fdtab[si->fd].state == FD_STCONN)