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