Ejemplo n.º 1
0
func (p poller) Wait(duration time.Duration) ([]event, error) {
	const maxEvents = 64
	inEvents := make([]C.struct_kevent, maxEvents)
	n, err := C.kevent(C.int(p), nil, 0, (*C.struct_kevent)(unsafe.Pointer(&inEvents[0])), maxEvents, p.timespec(duration))
	if err != nil {
		if err == syscall.EINTR {
			err = nil
		}
		return nil, err
	}
	events := make([]event, int(n))
	for ii := 0; ii < int(n); ii++ {
		inEvent := inEvents[ii]
		var flags Flags
		if inEvent.filter&C.EVFILT_READ != 0 {
			flags |= In
		}
		if inEvent.filter&C.EVFILT_WRITE != 0 {
			flags |= Out
		}
		if inEvent.flags&C.EV_ONESHOT != 0 {
			flags |= OneShot
		}
		events[ii] = event{
			fd:    int(inEvent.ident),
			flags: flags,
		}
	}
	return events, nil
}
Ejemplo n.º 2
0
func (p poller) applyEvent(ev *C.struct_kevent) error {
	ok, err := C.kevent(C.int(p), ev, 1, nil, 0, p.timespec(0))
	if ok < 0 {
		return err
	}
	return nil
}