Changeset 5692 for pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c
- Timestamp:
- Nov 13, 2017 6:06:25 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c
r5680 r5692 38 38 #include <pj/rand.h> 39 39 40 #if !defined(PJ_LINUX_KERNEL) || PJ_LINUX_KERNEL==0 41 /* 42 * Linux user mode 43 */ 44 # include <sys/epoll.h> 45 # include <errno.h> 46 # include <unistd.h> 47 48 # define epoll_data data.ptr 49 # define epoll_data_type void* 50 # define ioctl_val_type unsigned long 51 # define getsockopt_val_ptr int* 52 # define os_getsockopt getsockopt 53 # define os_ioctl ioctl 54 # define os_read read 55 # define os_close close 56 # define os_epoll_create epoll_create 57 # define os_epoll_ctl epoll_ctl 58 # define os_epoll_wait epoll_wait 59 #else 60 /* 61 * Linux kernel mode. 62 */ 63 # include <linux/config.h> 64 # include <linux/version.h> 65 # if defined(MODVERSIONS) 66 # include <linux/modversions.h> 67 # endif 68 # include <linux/kernel.h> 69 # include <linux/poll.h> 70 # include <linux/eventpoll.h> 71 # include <linux/syscalls.h> 72 # include <linux/errno.h> 73 # include <linux/unistd.h> 74 # include <asm/ioctls.h> 75 enum EPOLL_EVENTS 76 { 77 EPOLLIN = 0x001, 78 EPOLLOUT = 0x004, 79 EPOLLERR = 0x008, 80 }; 81 # define os_epoll_create sys_epoll_create 82 static int os_epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) 83 { 84 long rc; 85 mm_segment_t oldfs = get_fs(); 86 set_fs(KERNEL_DS); 87 rc = sys_epoll_ctl(epfd, op, fd, event); 88 set_fs(oldfs); 89 if (rc) { 90 errno = -rc; 91 return -1; 92 } else { 93 return 0; 94 } 95 } 96 static int os_epoll_wait(int epfd, struct epoll_event *events, 97 int maxevents, int timeout) 98 { 99 int count; 100 mm_segment_t oldfs = get_fs(); 101 set_fs(KERNEL_DS); 102 count = sys_epoll_wait(epfd, events, maxevents, timeout); 103 set_fs(oldfs); 104 return count; 105 } 106 # define os_close sys_close 107 # define os_getsockopt pj_sock_getsockopt 108 static int os_read(int fd, void *buf, size_t len) 109 { 110 long rc; 111 mm_segment_t oldfs = get_fs(); 112 set_fs(KERNEL_DS); 113 rc = sys_read(fd, buf, len); 114 set_fs(oldfs); 115 if (rc) { 116 errno = -rc; 117 return -1; 118 } else { 119 return 0; 120 } 121 } 122 # define socklen_t unsigned 123 # define ioctl_val_type unsigned long 124 int ioctl(int fd, int opt, ioctl_val_type value); 125 static int os_ioctl(int fd, int opt, ioctl_val_type value) 126 { 127 int rc; 128 mm_segment_t oldfs = get_fs(); 129 set_fs(KERNEL_DS); 130 rc = ioctl(fd, opt, value); 131 set_fs(oldfs); 132 if (rc < 0) { 133 errno = -rc; 134 return rc; 135 } else 136 return rc; 137 } 138 # define getsockopt_val_ptr char* 139 140 # define epoll_data data 141 # define epoll_data_type __u32 142 #endif 40 #include <sys/epoll.h> 41 #include <errno.h> 42 #include <unistd.h> 43 44 #define epoll_data data.ptr 45 #define epoll_data_type void* 46 #define ioctl_val_type unsigned long 47 #define getsockopt_val_ptr int* 48 #define os_getsockopt getsockopt 49 #define os_ioctl ioctl 50 #define os_read read 51 #define os_close close 52 #define os_epoll_create epoll_create 53 #define os_epoll_ctl epoll_ctl 54 #define os_epoll_wait epoll_wait 143 55 144 56 #define THIS_FILE "ioq_epoll" … … 202 114 PJ_DEF(const char*) pj_ioqueue_name(void) 203 115 { 204 #if defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL!=0 205 return "epoll-kernel"; 206 #else 207 return "epoll"; 208 #endif 116 return "epoll"; 209 117 } 210 118
Note: See TracChangeset
for help on using the changeset viewer.