Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 2 | * include/types/fd.h |
| 3 | * File descriptors states. |
| 4 | * |
| 5 | * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu |
| 6 | * |
| 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 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _TYPES_FD_H |
| 23 | #define _TYPES_FD_H |
| 24 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 25 | #include <common/config.h> |
Willy Tarreau | dd2f85e | 2012-09-02 22:34:23 +0200 | [diff] [blame] | 26 | #include <types/port_range.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 27 | |
Willy Tarreau | 5446940 | 2006-07-29 16:59:06 +0200 | [diff] [blame] | 28 | enum { |
| 29 | DIR_RD=0, |
| 30 | DIR_WR=1, |
| 31 | DIR_SIZE |
| 32 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 34 | /* |
| 35 | * FD_POLL_IN remains set as long as some data is pending for read. |
| 36 | * FD_POLL_OUT remains set as long as the fd accepts to write data. |
| 37 | * FD_POLL_ERR and FD_POLL_ERR remain set forever (until processed). |
| 38 | */ |
Willy Tarreau | 3d32d3a | 2007-04-15 11:31:05 +0200 | [diff] [blame] | 39 | #define FD_POLL_IN 0x01 |
| 40 | #define FD_POLL_PRI 0x02 |
| 41 | #define FD_POLL_OUT 0x04 |
| 42 | #define FD_POLL_ERR 0x08 |
| 43 | #define FD_POLL_HUP 0x10 |
Willy Tarreau | 3d32d3a | 2007-04-15 11:31:05 +0200 | [diff] [blame] | 44 | |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 45 | #define FD_POLL_DATA (FD_POLL_IN | FD_POLL_OUT) |
| 46 | #define FD_POLL_STICKY (FD_POLL_ERR | FD_POLL_HUP) |
Willy Tarreau | 3d32d3a | 2007-04-15 11:31:05 +0200 | [diff] [blame] | 47 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 48 | /* info about one given fd */ |
| 49 | struct fdtab { |
Willy Tarreau | 4e6049e | 2012-07-06 10:53:51 +0200 | [diff] [blame] | 50 | int (*iocb)(int fd); /* I/O handler, returns FD_WAIT_* */ |
Willy Tarreau | 8018471 | 2012-07-06 14:54:49 +0200 | [diff] [blame] | 51 | void *owner; /* the connection or listener associated with this fd, NULL if closed */ |
Willy Tarreau | 45dab73 | 2012-09-02 22:19:18 +0200 | [diff] [blame] | 52 | unsigned int spec_p; /* speculative polling: position in spec list+1. 0=not in list. */ |
| 53 | unsigned char spec_e; /* speculative polling: read and write events status. 4 bits */ |
Willy Tarreau | 3d32d3a | 2007-04-15 11:31:05 +0200 | [diff] [blame] | 54 | unsigned char ev; /* event seen in return of poll() : FD_POLL_* */ |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | /* less often used information */ |
| 58 | struct fdinfo { |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 59 | struct port_range *port_range; /* optional port range to bind to */ |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 60 | int local_port; /* optional local port */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 61 | }; |
| 62 | |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 63 | /* |
| 64 | * Poller descriptors. |
| 65 | * - <name> is initialized by the poller's register() function, and should not |
| 66 | * be allocated, just linked to. |
| 67 | * - <pref> is initialized by the poller's register() function. It is set to 0 |
| 68 | * by default, meaning the poller is disabled. init() should set it to 0 in |
| 69 | * case of failure. term() must set it to 0. A generic unoptimized select() |
| 70 | * poller should set it to 100. |
| 71 | * - <private> is initialized by the poller's init() function, and cleaned by |
| 72 | * the term() function. |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 73 | * - clo() should be used to do indicate the poller that fd will be closed. It |
| 74 | * may be the same as rem() on some pollers. |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 75 | * - poll() calls the poller, expiring at <exp> |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 76 | */ |
| 77 | struct poller { |
| 78 | void *private; /* any private data for the poller */ |
Willy Tarreau | 5b70242 | 2007-04-16 01:33:26 +0200 | [diff] [blame] | 79 | int REGPRM2 (*is_set)(const int fd, int dir); /* check if <fd> is being polled for dir <dir> */ |
Willy Tarreau | 3788e4c | 2012-07-30 14:29:35 +0200 | [diff] [blame] | 80 | void REGPRM2 (*set)(const int fd, int dir); /* set polling on <fd> for <dir> */ |
| 81 | void REGPRM2 (*clr)(const int fd, int dir); /* clear polling on <fd> for <dir> */ |
Willy Tarreau | babd05a | 2012-08-09 12:14:03 +0200 | [diff] [blame] | 82 | void REGPRM2 (*wai)(const int fd, int dir); /* wait for polling on <fd> for <dir> */ |
Willy Tarreau | 5b70242 | 2007-04-16 01:33:26 +0200 | [diff] [blame] | 83 | void REGPRM1 (*rem)(const int fd); /* remove any polling on <fd> */ |
| 84 | void REGPRM1 (*clo)(const int fd); /* mark <fd> as closed */ |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 85 | void REGPRM2 (*poll)(struct poller *p, int exp); /* the poller itself */ |
Willy Tarreau | 5b70242 | 2007-04-16 01:33:26 +0200 | [diff] [blame] | 86 | int REGPRM1 (*init)(struct poller *p); /* poller initialization */ |
| 87 | void REGPRM1 (*term)(struct poller *p); /* termination of this poller */ |
| 88 | int REGPRM1 (*test)(struct poller *p); /* pre-init check of the poller */ |
| 89 | int REGPRM1 (*fork)(struct poller *p); /* post-fork re-opening */ |
Willy Tarreau | 4f60f16 | 2007-04-08 16:39:58 +0200 | [diff] [blame] | 90 | const char *name; /* poller name */ |
| 91 | int pref; /* try pollers with higher preference first */ |
| 92 | }; |
| 93 | |
| 94 | extern struct poller cur_poller; /* the current poller */ |
| 95 | extern int nbpollers; |
| 96 | #define MAX_POLLERS 10 |
| 97 | extern struct poller pollers[MAX_POLLERS]; /* all registered pollers */ |
| 98 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 99 | extern struct fdtab *fdtab; /* array of all the file descriptors */ |
Willy Tarreau | 8d5d77e | 2009-10-18 07:25:52 +0200 | [diff] [blame] | 100 | extern struct fdinfo *fdinfo; /* less-often used infos for file descriptors */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 101 | extern int maxfd; /* # of the highest fd + 1 */ |
| 102 | extern int totalconn; /* total # of terminated sessions */ |
| 103 | extern int actconn; /* # of active sessions */ |
| 104 | |
| 105 | #endif /* _TYPES_FD_H */ |
| 106 | |
| 107 | /* |
| 108 | * Local variables: |
| 109 | * c-indent-level: 8 |
| 110 | * c-basic-offset: 8 |
| 111 | * End: |
| 112 | */ |