]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: sock_raw: remove last references to stream_sock
authorWilly Tarreau <w@1wt.eu>
Fri, 11 May 2012 14:59:14 +0000 (16:59 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 11 May 2012 15:03:42 +0000 (17:03 +0200)
We also stop exporting all functions since they're not needed anymore outside
of sock_raw.c.

include/proto/sock_raw.h
src/backend.c
src/peers.c
src/session.c
src/sock_raw.c

index a17db4dca7780c5ed307247422c9bbcd69202a61..0d8b8780b56f219db0bd1efdb03bfd671d7df11a 100644 (file)
@@ -2,7 +2,7 @@
  * include/proto/sock_raw.h
  * This file contains definition for raw stream socket operations
  *
- * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef _PROTO_STREAM_SOCK_H
-#define _PROTO_STREAM_SOCK_H
+#ifndef _PROTO_SOCK_RAW_H
+#define _PROTO_SOCK_RAW_H
 
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <common/config.h>
 #include <types/stream_interface.h>
 
+extern struct sock_ops sock_raw;
 
-/* main event functions used to move data between sockets and buffers */
-int stream_sock_read(int fd);
-int stream_sock_write(int fd);
-void stream_sock_data_finish(struct stream_interface *si);
-void stream_sock_shutr(struct stream_interface *si);
-void stream_sock_shutw(struct stream_interface *si);
-void stream_sock_chk_rcv(struct stream_interface *si);
-void stream_sock_chk_snd(struct stream_interface *si);
-
-extern struct sock_ops stream_sock;
-
-/* This either returns the sockname or the original destination address. Code
- * inspired from Patrick Schaaf's example of nf_getsockname() implementation.
- */
-static inline int get_original_dst(int fd, struct sockaddr_in *sa, socklen_t *salen) {
-#if defined(TPROXY) && defined(SO_ORIGINAL_DST)
-    return getsockopt(fd, SOL_IP, SO_ORIGINAL_DST, (void *)sa, salen);
-#else
-#if defined(TPROXY) && defined(USE_GETSOCKNAME)
-    return getsockname(fd, (struct sockaddr *)sa, salen);
-#else
-    return -1;
-#endif
-#endif
-}
-
-#endif /* _PROTO_STREAM_SOCK_H */
+#endif /* _PROTO_SOCK_RAW_H */
 
 /*
  * Local variables:
index 928d63e2530762f1e553c50776e8817316e08337..9467b2d0b065d5688d2ad72cfa391ba561ef3e8b 100644 (file)
@@ -974,7 +974,7 @@ int connect_server(struct session *s)
         * decide here if we can reuse the connection by comparing the
         * session's freshly assigned target with the stream interface's.
         */
-       stream_interface_prepare(s->req->cons, &stream_sock);
+       stream_interface_prepare(s->req->cons, &sock_raw);
 
        /* the target was only on the session, assign it to the SI now */
        copy_target(&s->req->cons->target, &s->target);
index 6d84b4e458ac8ebadf0290ea8f9f3a8a42045e01..016a05f40233a57f8432a3d51ab5246d450622a3 100644 (file)
@@ -1182,7 +1182,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
        if (s->be->options2 & PR_O2_INDEPSTR)
                s->si[1].flags |= SI_FL_INDEP_STR;
 
-       stream_interface_prepare(&s->si[1], &stream_sock);
+       stream_interface_prepare(&s->si[1], &sock_raw);
 
        session_init_srv_conn(s);
        set_target_proxy(&s->target, s->be);
index 77fc32e8e1580b57e71f80a3a463c6832415c6e2..2cb8b664eb4a3d9cd498af9ef644e08bcfefa512 100644 (file)
@@ -184,7 +184,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
                s->si[0].flags = SI_FL_CAP_SPLTCP; /* TCP/TCPv6 splicing possible */
 
        /* add the various callbacks */
-       stream_interface_prepare(&s->si[0], &stream_sock);
+       stream_interface_prepare(&s->si[0], &sock_raw);
 
        /* pre-initialize the other side's stream interface to an INIT state. The
         * callbacks will be initialized before attempting to connect.
index 37d6f3796a76edcb0ec244f3f74a7c672be821fd..7e0d4c9a477b4d53fb5ee22c2983f170c68a55eb 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * Functions operating on SOCK_STREAM and buffers.
+ * Functions used to send/receive data using SOCK_STREAM sockets.
  *
- * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
 
 #include <types/global.h>
 
+/* main event functions used to move data between sockets and buffers */
+static int sock_raw_read(int fd);
+static int sock_raw_write(int fd);
+static void sock_raw_data_finish(struct stream_interface *si);
+static void sock_raw_shutr(struct stream_interface *si);
+static void sock_raw_shutw(struct stream_interface *si);
+static void sock_raw_chk_rcv(struct stream_interface *si);
+static void sock_raw_chk_snd(struct stream_interface *si);
+
+
 #if defined(CONFIG_HAP_LINUX_SPLICE)
 #include <common/splice.h>
 
@@ -71,7 +81,7 @@
  * This function automatically allocates a pipe from the pipe pool. It also
  * carefully ensures to clear b->pipe whenever it leaves the pipe empty.
  */
-static int stream_sock_splice_in(struct buffer *b, struct stream_interface *si)
+static int sock_raw_splice_in(struct buffer *b, struct stream_interface *si)
 {
        static int splice_detects_close;
        int fd = si->fd;
@@ -216,14 +226,15 @@ static int stream_sock_splice_in(struct buffer *b, struct stream_interface *si)
  * able to read more data without polling first. Returns non-zero
  * otherwise.
  */
-int stream_sock_read(int fd) {
+static int sock_raw_read(int fd)
+{
        struct stream_interface *si = fdtab[fd].owner;
        struct buffer *b = si->ib;
        int ret, max, retval, cur_read;
        int read_poll = MAX_READ_POLL_LOOPS;
 
 #ifdef DEBUG_FULL
-       fprintf(stderr,"stream_sock_read : fd=%d, ev=0x%02x, owner=%p\n", fd, fdtab[fd].ev, fdtab[fd].owner);
+       fprintf(stderr,"sock_raw_read : fd=%d, ev=0x%02x, owner=%p\n", fd, fdtab[fd].ev, fdtab[fd].owner);
 #endif
 
        retval = 1;
@@ -255,7 +266,7 @@ int stream_sock_read(int fd) {
                if (fdtab[fd].ev & FD_POLL_HUP)
                        goto out_shutdown_r;
 
-               retval = stream_sock_splice_in(b, si);
+               retval = sock_raw_splice_in(b, si);
 
                if (retval >= 0) {
                        if (si->flags & SI_FL_ERR)
@@ -479,7 +490,7 @@ int stream_sock_read(int fd) {
        b->flags |= BF_READ_NULL;
        if (b->flags & BF_AUTO_CLOSE)
                buffer_shutw_now(b);
-       stream_sock_shutr(si);
+       sock_raw_shutr(si);
        goto out_wakeup;
 
  out_error:
@@ -505,7 +516,7 @@ int stream_sock_read(int fd) {
  * before calling it again, otherwise 1. If a pipe was associated with the
  * buffer and it empties it, it releases it as well.
  */
-static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b)
+static int sock_raw_write_loop(struct stream_interface *si, struct buffer *b)
 {
        int write_poll = MAX_WRITE_POLL_LOOPS;
        int retval = 1;
@@ -685,14 +696,14 @@ static int stream_sock_write_loop(struct stream_interface *si, struct buffer *b)
  * It returns 0 if the caller needs to poll before calling it again, otherwise
  * non-zero.
  */
-int stream_sock_write(int fd)
+static int sock_raw_write(int fd)
 {
        struct stream_interface *si = fdtab[fd].owner;
        struct buffer *b = si->ob;
        int retval = 1;
 
 #ifdef DEBUG_FULL
-       fprintf(stderr,"stream_sock_write : fd=%d, owner=%p\n", fd, fdtab[fd].owner);
+       fprintf(stderr,"sock_raw_write : fd=%d, owner=%p\n", fd, fdtab[fd].owner);
 #endif
 
        retval = 1;
@@ -705,7 +716,7 @@ int stream_sock_write(int fd)
 
        if (likely(!(b->flags & BF_OUT_EMPTY) || si->send_proxy_ofs)) {
                /* OK there are data waiting to be sent */
-               retval = stream_sock_write_loop(si, b);
+               retval = sock_raw_write_loop(si, b);
                if (retval < 0)
                        goto out_error;
                else if (retval == 0 && si->send_proxy_ofs)
@@ -757,7 +768,7 @@ int stream_sock_write(int fd)
                 */
                if (((b->flags & (BF_SHUTW|BF_HIJACK|BF_SHUTW_NOW)) == BF_SHUTW_NOW) &&
                    (si->state == SI_ST_EST)) {
-                       stream_sock_shutw(si);
+                       sock_raw_shutw(si);
                        goto out_wakeup;
                }
                
@@ -828,7 +839,7 @@ int stream_sock_write(int fd)
  * updated to reflect the new state. It does also close everything is the SI was
  * marked as being in error state.
  */
-void stream_sock_shutw(struct stream_interface *si)
+static void sock_raw_shutw(struct stream_interface *si)
 {
        si->ob->flags &= ~BF_SHUTW_NOW;
        if (si->ob->flags & BF_SHUTW)
@@ -888,7 +899,7 @@ void stream_sock_shutw(struct stream_interface *si)
  * or closes the file descriptor and marks itself as closed. The buffer flags are
  * updated to reflect the new state.
  */
-void stream_sock_shutr(struct stream_interface *si)
+static void sock_raw_shutr(struct stream_interface *si)
 {
        si->ib->flags &= ~BF_SHUTR_NOW;
        if (si->ib->flags & BF_SHUTR)
@@ -914,12 +925,12 @@ void stream_sock_shutr(struct stream_interface *si)
 }
 
 /*
- * Updates a connected stream_sock file descriptor status and timeouts
+ * Updates a connected sock_raw file descriptor status and timeouts
  * according to the buffers' flags. It should only be called once after the
  * buffer flags have settled down, and before they are cleared. It doesn't
  * harm to call it as often as desired (it just slightly hurts performance).
  */
-void stream_sock_data_finish(struct stream_interface *si)
+static void sock_raw_data_finish(struct stream_interface *si)
 {
        struct buffer *ib = si->ib;
        struct buffer *ob = si->ob;
@@ -999,7 +1010,7 @@ void stream_sock_data_finish(struct stream_interface *si)
  * for free space in the buffer. Note that it intentionally does not update
  * timeouts, so that we can still check them later at wake-up.
  */
-void stream_sock_chk_rcv(struct stream_interface *si)
+static void sock_raw_chk_rcv(struct stream_interface *si)
 {
        struct buffer *ib = si->ib;
 
@@ -1033,7 +1044,7 @@ void stream_sock_chk_rcv(struct stream_interface *si)
  * for data in the buffer. Note that it intentionally does not update timeouts,
  * so that we can still check them later at wake-up.
  */
-void stream_sock_chk_snd(struct stream_interface *si)
+static void sock_raw_chk_snd(struct stream_interface *si)
 {
        struct buffer *ob = si->ob;
        int retval;
@@ -1057,7 +1068,7 @@ void stream_sock_chk_snd(struct stream_interface *si)
             (fdtab[si->fd].ev & FD_POLL_OUT)))   /* we'll be called anyway */
                return;
 
-       retval = stream_sock_write_loop(si, ob);
+       retval = sock_raw_write_loop(si, ob);
        /* here, we have :
         *   retval < 0 if an error was encountered during write.
         *   retval = 0 if we can't write anymore without polling
@@ -1089,7 +1100,7 @@ void stream_sock_chk_snd(struct stream_interface *si)
                if (((ob->flags & (BF_SHUTW|BF_HIJACK|BF_AUTO_CLOSE|BF_SHUTW_NOW)) ==
                     (BF_AUTO_CLOSE|BF_SHUTW_NOW)) &&
                    (si->state == SI_ST_EST)) {
-                       stream_sock_shutw(si);
+                       sock_raw_shutw(si);
                        goto out_wakeup;
                }
 
@@ -1139,14 +1150,14 @@ void stream_sock_chk_snd(struct stream_interface *si)
 }
 
 /* stream sock operations */
-struct sock_ops stream_sock = {
-       .update  = stream_sock_data_finish,
-       .shutr   = stream_sock_shutr,
-       .shutw   = stream_sock_shutw,
-       .chk_rcv = stream_sock_chk_rcv,
-       .chk_snd = stream_sock_chk_snd,
-       .read    = stream_sock_read,
-       .write   = stream_sock_write,
+struct sock_ops sock_raw = {
+       .update  = sock_raw_data_finish,
+       .shutr   = sock_raw_shutr,
+       .shutw   = sock_raw_shutw,
+       .chk_rcv = sock_raw_chk_rcv,
+       .chk_snd = sock_raw_chk_snd,
+       .read    = sock_raw_read,
+       .write   = sock_raw_write,
 };
 
 /*