xref: /libevent-2.1.12/epoll_sub.c (revision dfe1e526)
128d248e0SNiels Provos /*
2b85b710cSNick Mathewson  * Copyright 2003-2009 Niels Provos <[email protected]>
3e49e2891SNick Mathewson  * Copyright 2009-2012 Niels Provos and Nick Mathewson
428d248e0SNiels Provos  *
528d248e0SNiels Provos  * Redistribution and use in source and binary forms, with or without
628d248e0SNiels Provos  * modification, are permitted provided that the following conditions
728d248e0SNiels Provos  * are met:
828d248e0SNiels Provos  * 1. Redistributions of source code must retain the above copyright
928d248e0SNiels Provos  *    notice, this list of conditions and the following disclaimer.
1028d248e0SNiels Provos  * 2. Redistributions in binary form must reproduce the above copyright
1128d248e0SNiels Provos  *    notice, this list of conditions and the following disclaimer in the
1228d248e0SNiels Provos  *    documentation and/or other materials provided with the distribution.
13c3f496c7SNiels Provos  * 3. The name of the author may not be used to endorse or promote products
1428d248e0SNiels Provos  *    derived from this software without specific prior written permission.
1528d248e0SNiels Provos  *
1628d248e0SNiels Provos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1728d248e0SNiels Provos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1828d248e0SNiels Provos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1928d248e0SNiels Provos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2028d248e0SNiels Provos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2128d248e0SNiels Provos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2228d248e0SNiels Provos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2328d248e0SNiels Provos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2428d248e0SNiels Provos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2528d248e0SNiels Provos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2628d248e0SNiels Provos  */
273e41f17aSNiels Provos #include "evconfig-private.h"
283e41f17aSNiels Provos #include <stdint.h>
293e41f17aSNiels Provos 
303e41f17aSNiels Provos #include <sys/param.h>
313e41f17aSNiels Provos #include <sys/types.h>
323e41f17aSNiels Provos #include <sys/syscall.h>
333e41f17aSNiels Provos #include <sys/epoll.h>
34*dfe1e526SMarcin Juszkiewicz #include <unistd.h>
353e41f17aSNiels Provos #include <errno.h>
363e41f17aSNiels Provos 
373e41f17aSNiels Provos int
epoll_create(int size)383e41f17aSNiels Provos epoll_create(int size)
39*dfe1e526SMarcin Juszkiewicz {
40*dfe1e526SMarcin Juszkiewicz #if !defined(__NR_epoll_create) && defined(__NR_epoll_create1)
41*dfe1e526SMarcin Juszkiewicz 	if (size <= 0) {
42*dfe1e526SMarcin Juszkiewicz 		errno = EINVAL;
43*dfe1e526SMarcin Juszkiewicz 		return -1;
44*dfe1e526SMarcin Juszkiewicz 	}
45*dfe1e526SMarcin Juszkiewicz 	return (syscall(__NR_epoll_create1, 0));
463e41f17aSNiels Provos #else
47*dfe1e526SMarcin Juszkiewicz 	return (syscall(__NR_epoll_create, size));
483e41f17aSNiels Provos #endif
493e41f17aSNiels Provos }
503e41f17aSNiels Provos 
513e41f17aSNiels Provos int
epoll_ctl(int epfd,int op,int fd,struct epoll_event * event)523e41f17aSNiels Provos epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
533e41f17aSNiels Provos {
543e41f17aSNiels Provos 
553e41f17aSNiels Provos 	return (syscall(__NR_epoll_ctl, epfd, op, fd, event));
563e41f17aSNiels Provos }
573e41f17aSNiels Provos 
583e41f17aSNiels Provos int
epoll_wait(int epfd,struct epoll_event * events,int maxevents,int timeout)593e41f17aSNiels Provos epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
60*dfe1e526SMarcin Juszkiewicz {
61*dfe1e526SMarcin Juszkiewicz #if !defined(__NR_epoll_wait) && defined(__NR_epoll_pwait)
62*dfe1e526SMarcin Juszkiewicz 	return (syscall(__NR_epoll_pwait, epfd, events, maxevents, timeout, NULL, 0));
633e41f17aSNiels Provos #else
64*dfe1e526SMarcin Juszkiewicz 	return (syscall(__NR_epoll_wait, epfd, events, maxevents, timeout));
653e41f17aSNiels Provos #endif
66 }
67