2011-10-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / syscalls / socket_epoll.go
blob0013f33498f46479594a28ea2da850f2e74d3ff6
1 // socket_epoll.go -- GNU/Linux epoll handling.
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Support for GNU/Linux epoll.
8 // Only for implementing net package.
9 // DO NOT USE DIRECTLY.
11 package syscall
13 // We don't take this type directly from the header file because it
14 // uses a union. FIXME.
16 type EpollEvent struct {
17 Events uint32;
18 Fd int32;
19 Pad int32;
22 func libc_epoll_create(size int) int __asm__ ("epoll_create");
23 func libc_epoll_ctl(epfd, op, fd int, event *EpollEvent) int __asm__ ("epoll_ctl");
24 func libc_epoll_wait(epfd int, events *EpollEvent, maxevents int,
25 timeout int) int __asm__ ("epoll_wait");
28 func EpollCreate(size int) (fd int, errno int) {
29 fd = libc_epoll_create(int(size));
30 if fd < 0 { errno = GetErrno() }
31 return;
34 func EpollCtl(epfd, op, fd int, ev *EpollEvent) (errno int) {
35 r := libc_epoll_ctl(epfd, op, fd, ev);
36 if r < 0 { errno = GetErrno() }
37 return;
40 func EpollWait(epfd int, ev []EpollEvent, msec int) (n int, errno int) {
41 var events *EpollEvent;
42 var maxevents int;
43 if len(ev) > 0 {
44 maxevents = len(ev);
45 events = &ev[0]
47 n = libc_epoll_wait(epfd, events, maxevents, msec);
48 if n < 0 { errno = GetErrno() }
49 return;