Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 2 | * include/common/epoll.h |
| 3 | * epoll definitions for older libc. |
| 4 | * |
| 5 | * Copyright (C) 2000-2011 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 | /* |
| 23 | * Those constants were found both in glibc and in the Linux kernel. |
| 24 | * They are provided here because the epoll() syscall is featured in |
| 25 | * some kernels but in not often included in the glibc, so it needs |
| 26 | * just a basic definition. |
| 27 | */ |
| 28 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 29 | #ifndef _COMMON_EPOLL_H |
| 30 | #define _COMMON_EPOLL_H |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 32 | #if defined (__linux__) && (defined(ENABLE_EPOLL) || defined(ENABLE_SEPOLL)) |
| 33 | |
| 34 | #ifndef USE_MY_EPOLL |
| 35 | #include <sys/epoll.h> |
| 36 | #else |
| 37 | |
| 38 | #include <errno.h> |
Willy Tarreau | 014b4fe | 2006-10-15 22:57:13 +0200 | [diff] [blame] | 39 | #include <sys/types.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 40 | #include <linux/unistd.h> |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 41 | #include <sys/syscall.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 42 | #include <common/config.h> |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 43 | #include <common/syscall.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | |
| 45 | /* epoll_ctl() commands */ |
| 46 | #ifndef EPOLL_CTL_ADD |
| 47 | #define EPOLL_CTL_ADD 1 |
| 48 | #define EPOLL_CTL_DEL 2 |
| 49 | #define EPOLL_CTL_MOD 3 |
| 50 | #endif |
| 51 | |
| 52 | /* events types (bit fields) */ |
| 53 | #ifndef EPOLLIN |
| 54 | #define EPOLLIN 1 |
| 55 | #define EPOLLPRI 2 |
| 56 | #define EPOLLOUT 4 |
| 57 | #define EPOLLERR 8 |
| 58 | #define EPOLLHUP 16 |
| 59 | #define EPOLLONESHOT (1 << 30) |
| 60 | #define EPOLLET (1 << 31) |
| 61 | #endif |
| 62 | |
| 63 | struct epoll_event { |
| 64 | uint32_t events; |
| 65 | union { |
| 66 | void *ptr; |
| 67 | int fd; |
| 68 | uint32_t u32; |
| 69 | uint64_t u64; |
| 70 | } data; |
| 71 | }; |
| 72 | |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 73 | #if defined(CONFIG_HAP_LINUX_VSYSCALL) && defined(__linux__) && defined(__i386__) |
| 74 | /* Those are our self-defined functions */ |
| 75 | extern int epoll_create(int size); |
| 76 | extern int epoll_ctl(int epfd, int op, int fd, struct epoll_event * event); |
| 77 | extern int epoll_wait(int epfd, struct epoll_event * events, int maxevents, int timeout); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 78 | #else |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 79 | |
| 80 | /* We'll define a syscall, so for this we need __NR_splice. It should have |
| 81 | * been provided by syscall.h. |
| 82 | */ |
| 83 | #if !defined(__NR_epoll_ctl) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 84 | #warning unsupported architecture, guessing __NR_epoll_create=254 like x86... |
| 85 | #define __NR_epoll_create 254 |
| 86 | #define __NR_epoll_ctl 255 |
| 87 | #define __NR_epoll_wait 256 |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 88 | #endif /* __NR_epoll_ctl */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 89 | |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 90 | static inline _syscall1 (int, epoll_create, int, size); |
| 91 | static inline _syscall4 (int, epoll_ctl, int, epfd, int, op, int, fd, struct epoll_event *, event); |
| 92 | static inline _syscall4 (int, epoll_wait, int, epfd, struct epoll_event *, events, int, maxevents, int, timeout); |
| 93 | #endif /* VSYSCALL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 94 | |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 95 | #endif /* USE_MY_EPOLL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 96 | |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 97 | #endif /* __linux__ && (ENABLE_EPOLL || ENABLE_SEPOLL) */ |
| 98 | |
| 99 | #endif /* _COMMON_EPOLL_H */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * Local variables: |
| 103 | * c-indent-level: 8 |
| 104 | * c-basic-offset: 8 |
| 105 | * End: |
| 106 | */ |