blob: 68335c033c878be60af5d9846b940b359699c656 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreaue3ba5f02006-06-29 18:54:54 +02002 include/types/fd.h
Willy Tarreaubaaee002006-06-26 02:48:02 +02003 File descriptors states.
4
Willy Tarreau63455a92007-04-09 15:34:49 +02005 Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02006
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation, version 2.1
10 exclusively.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#ifndef _TYPES_FD_H
23#define _TYPES_FD_H
24
25#include <sys/time.h>
26#include <sys/types.h>
27#include <unistd.h>
28
Willy Tarreau2dd0d472006-06-29 17:53:05 +020029#include <common/config.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030#include <types/task.h>
Willy Tarreau54469402006-07-29 16:59:06 +020031#include <types/buffers.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020032
33/* different possible states for the fd */
34#define FD_STCLOSE 0
35#define FD_STLISTEN 1
36#define FD_STCONN 2
37#define FD_STREADY 3
38#define FD_STERROR 4
39
Willy Tarreau54469402006-07-29 16:59:06 +020040enum {
41 DIR_RD=0,
42 DIR_WR=1,
43 DIR_SIZE
44};
Willy Tarreaubaaee002006-06-26 02:48:02 +020045
46/* info about one given fd */
47struct fdtab {
Willy Tarreau54469402006-07-29 16:59:06 +020048 struct {
49 int (*f)(int fd); /* read/write function */
50 struct buffer *b; /* read/write buffer */
51 } cb[DIR_SIZE];
52 struct task *owner; /* the session (or proxy) associated with this fd */
53 int state; /* the state of this fd */
Willy Tarreaubaaee002006-06-26 02:48:02 +020054};
55
Willy Tarreau4f60f162007-04-08 16:39:58 +020056/*
57 * Poller descriptors.
58 * - <name> is initialized by the poller's register() function, and should not
59 * be allocated, just linked to.
60 * - <pref> is initialized by the poller's register() function. It is set to 0
61 * by default, meaning the poller is disabled. init() should set it to 0 in
62 * case of failure. term() must set it to 0. A generic unoptimized select()
63 * poller should set it to 100.
64 * - <private> is initialized by the poller's init() function, and cleaned by
65 * the term() function.
Willy Tarreau97129b52007-04-09 00:54:46 +020066 * - cond_s() checks if fd was not set then sets it and returns 1. Otherwise
67 * it returns 0. It may be the same as set().
68 * - cond_c() checks if fd was set then clears it and returns 1. Otherwise
69 * it returns 0. It may be the same as clr().
Willy Tarreau4f60f162007-04-08 16:39:58 +020070 * - clo() should be used to do indicate the poller that fd will be closed. It
71 * may be the same as rem() on some pollers.
72 * - poll() calls the poller, waiting at most wait_time ms.
73 */
74struct poller {
75 void *private; /* any private data for the poller */
Willy Tarreau63455a92007-04-09 15:34:49 +020076 REGPRM2 int (*is_set)(const int fd, int dir); /* check if <fd> is being polled for dir <dir> */
Willy Tarreau97129b52007-04-09 00:54:46 +020077 REGPRM2 int (*set)(const int fd, int dir); /* set polling on <fd> for <dir> */
78 REGPRM2 int (*clr)(const int fd, int dir); /* clear polling on <fd> for <dir> */
79 REGPRM2 int (*cond_s)(const int fd, int dir); /* set polling on <fd> for <dir> if unset */
80 REGPRM2 int (*cond_c)(const int fd, int dir); /* clear polling on <fd> for <dir> if set */
Willy Tarreau4f60f162007-04-08 16:39:58 +020081 REGPRM1 void (*rem)(const int fd); /* remove any polling on <fd> */
82 REGPRM1 void (*clo)(const int fd); /* mark <fd> as closed */
83 REGPRM2 void (*poll)(struct poller *p, int wait_time); /* the poller itself */
84 REGPRM1 int (*init)(struct poller *p); /* poller initialization */
85 REGPRM1 void (*term)(struct poller *p); /* termination of this poller */
86 const char *name; /* poller name */
87 int pref; /* try pollers with higher preference first */
88};
89
90extern struct poller cur_poller; /* the current poller */
91extern int nbpollers;
92#define MAX_POLLERS 10
93extern struct poller pollers[MAX_POLLERS]; /* all registered pollers */
94
Willy Tarreaubaaee002006-06-26 02:48:02 +020095extern struct fdtab *fdtab; /* array of all the file descriptors */
96extern int maxfd; /* # of the highest fd + 1 */
97extern int totalconn; /* total # of terminated sessions */
98extern int actconn; /* # of active sessions */
99
100#endif /* _TYPES_FD_H */
101
102/*
103 * Local variables:
104 * c-indent-level: 8
105 * c-basic-offset: 8
106 * End:
107 */