]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add a handler for fd-based connections
authorWilly Tarreau <wtarreau@exceliance.fr>
Fri, 6 Jul 2012 12:13:49 +0000 (14:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Sep 2012 19:51:28 +0000 (21:51 +0200)
This connection handler will be used as an I/O handler for events
detected on a file descriptor. It is not used yet.

Makefile
Makefile.bsd
Makefile.osx
include/proto/connection.h [new file with mode: 0644]
src/connection.c [new file with mode: 0644]

index 7cc1708e4227892ecd1213acc0d4f4c0bc1b3d9b..f73c8da2389ee59d4a8d3d246b5b004ed81d45ec 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -543,7 +543,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
        src/uri_auth.o src/standard.o src/buffers.o src/log.o src/task.o \
        src/time.o src/fd.o src/pipe.o src/regex.o src/cfgparse.o src/server.o \
        src/checks.o src/queue.o src/frontend.o src/proxy.o src/peers.o \
-       src/arg.o src/stick_table.o src/proto_uxst.o \
+       src/arg.o src/stick_table.o src/proto_uxst.o src/connection.o \
        src/proto_http.o src/sock_raw.o src/appsession.o src/backend.o \
        src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o \
        src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
index 369178d51590f0cd581f4d53d9495949e201af4e..acfdd2a0a935e9578973b2ef4d47dcbe606a5338 100644 (file)
@@ -113,7 +113,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
        src/peers.o src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
        src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \
        src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o \
-       src/ev_poll.o src/ev_kqueue.o \
+       src/ev_poll.o src/ev_kqueue.o src/connection.o \
        src/arg.o src/acl.o src/memory.o src/freq_ctr.o \
        src/auth.o src/stick_table.o src/sample.o
 
index 76da19e5d12c684489ff6a417cb0f5d13a7e63c5..31a7f99d7206e9357909ca9d77c910808eb51a14 100644 (file)
@@ -110,7 +110,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
        src/peers.o src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
        src/session.o src/hdr_idx.o src/ev_select.o src/signal.o \
        src/lb_chash.o src/lb_fwlc.o src/lb_fwrr.o src/lb_map.o src/lb_fas.o \
-       src/ev_poll.o \
+       src/ev_poll.o src/connection.o \
        src/arg.o src/acl.o src/memory.o src/freq_ctr.o \
        src/auth.o src/stick_table.o src/sample.o
 
diff --git a/include/proto/connection.h b/include/proto/connection.h
new file mode 100644 (file)
index 0000000..b080449
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * include/proto/connection.h
+ * This file contains connection function prototypes
+ *
+ * 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
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _PROTO_CONNECTION_H
+#define _PROTO_CONNECTION_H
+
+#include <common/config.h>
+#include <types/connection.h>
+
+/* I/O callback for fd-based connections. It calls the read/write handlers
+ * provided by the connection's sock_ops. Returns FD_WAIT_*.
+ */
+int conn_fd_handler(int fd);
+
+#endif /* _PROTO_CONNECTION_H */
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ * End:
+ */
diff --git a/src/connection.c b/src/connection.c
new file mode 100644 (file)
index 0000000..a35e322
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Connection management functions
+ *
+ * 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
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <common/compat.h>
+#include <common/config.h>
+
+#include <types/connection.h>
+#include <types/stream_interface.h>
+
+/* 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
+ * FD_WAIT_*.
+ */
+int conn_fd_handler(int fd)
+{
+       struct stream_interface *si = fdtab[fd].owner;
+       int ret = 0;
+
+       if (!si)
+               return ret;
+
+       if (si->conn.flags & CO_FL_ERROR)
+               return ret;
+
+       if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
+               if (!si->conn.data->read(fd))
+                       ret |= FD_WAIT_READ;
+
+       if (si->conn.flags & CO_FL_ERROR)
+               return ret;
+
+       if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR))
+               if (!si->conn.data->write(fd))
+                       ret |= FD_WAIT_WRITE;
+
+       return ret;
+}