blob: a35e3220de9f1febf067063e41e67b0ed5942aa0 [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{
25 struct stream_interface *si = fdtab[fd].owner;
26 int ret = 0;
27
28 if (!si)
29 return ret;
30
31 if (si->conn.flags & CO_FL_ERROR)
32 return ret;
33
34 if (fdtab[fd].ev & (FD_POLL_IN | FD_POLL_HUP | FD_POLL_ERR))
35 if (!si->conn.data->read(fd))
36 ret |= FD_WAIT_READ;
37
38 if (si->conn.flags & CO_FL_ERROR)
39 return ret;
40
41 if (fdtab[fd].ev & (FD_POLL_OUT | FD_POLL_ERR))
42 if (!si->conn.data->write(fd))
43 ret |= FD_WAIT_WRITE;
44
45 return ret;
46}