blob: 696525d3e9c947b41b1852f96cd66924c940e631 [file] [log] [blame]
Willy Tarreau59f98392012-07-06 14:13:49 +02001/*
2 * Connection management functions
3 *
4 * Copyright 2000-2012 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <common/compat.h>
14#include <common/config.h>
15
16#include <types/connection.h>
17#include <types/stream_interface.h>
18
19/* I/O callback for fd-based connections. It calls the read/write handlers
20 * provided by the connection's sock_ops, which must be valid. It returns
21 * FD_WAIT_*.
22 */
23int conn_fd_handler(int fd)
24{
Willy Tarreau80184712012-07-06 14:54:49 +020025 struct connection *conn = fdtab[fd].owner;
Willy Tarreau59f98392012-07-06 14:13:49 +020026 int ret = 0;
27
Willy Tarreau80184712012-07-06 14:54:49 +020028 if (!conn)
Willy Tarreau59f98392012-07-06 14:13:49 +020029 return ret;
30
Willy Tarreau80184712012-07-06 14:54:49 +020031 if (conn->flags & CO_FL_ERROR)
Willy Tarreau59f98392012-07-06 14:13:49 +020032 return ret;
33
34 if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
Willy Tarreau80184712012-07-06 14:54:49 +020035 if (!conn->data->read(fd))
Willy Tarreau59f98392012-07-06 14:13:49 +020036 ret |= FD_WAIT_READ;
37
Willy Tarreau80184712012-07-06 14:54:49 +020038 if (conn->flags & CO_FL_ERROR)
Willy Tarreau59f98392012-07-06 14:13:49 +020039 return ret;
40
41 if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR))
Willy Tarreau80184712012-07-06 14:54:49 +020042 if (!conn->data->write(fd))
Willy Tarreau59f98392012-07-06 14:13:49 +020043 ret |= FD_WAIT_WRITE;
44
45 return ret;
46}