MINOR: connection: add a handler for fd-based connections

This connection handler will be used as an I/O handler for events
detected on a file descriptor. It is not used yet.
This commit is contained in:
Willy Tarreau 2012-07-06 14:13:49 +02:00 committed by Willy Tarreau
parent aece46a44d
commit 59f98393bb
5 changed files with 89 additions and 3 deletions

View File

@ -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 \

View 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

View 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

View File

@ -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:
*/

46
src/connection.c Normal file
View File

@ -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;
}