本文整理汇总了Golang中syscall.Kqueue函数的典型用法代码示例。如果您正苦于以下问题:Golang Kqueue函数的具体用法?Golang Kqueue怎么用?Golang Kqueue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Kqueue函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: kqueue
// kqueue creates a new kernel event queue and returns a descriptor.
func kqueue() (kq int, err error) {
kq, err = syscall.Kqueue()
if kq == -1 {
return kq, err
}
return kq, nil
}
示例2: runKqueue
func runKqueue() {
fd, err := syscall.Kqueue()
evTrackList := make([]syscall.Kevent_t, 1024)
if err != nil {
log.Fatal("error initializing Kqueue: ", err)
return
}
addFilesToKqueue(evTrackList, path)
// configure timeout
timeout := syscall.Timespec{
Sec: 0,
Nsec: 0,
}
// wait for events
for {
// create kevent
events := make([]syscall.Kevent_t, 10)
_, err := syscall.Kevent(fd, evTrackList, events, &timeout)
if err != nil {
log.Println("Error creating kevent")
}
// check if there was an event and process it
if len(events) > 0 && events[0].Ident > 0 {
processEvent()
}
}
}
示例3: NewPoll
func NewPoll() (p *pollster, err error) {
p = new(pollster)
if p.kq, err = syscall.Kqueue(); err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
syscall.CloseOnExec(p.kq)
return p, nil
}
示例4: newpollster
func newpollster() (p *pollster, err error) {
p = new(pollster)
if p.kq, err = syscall.Kqueue(); err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
syscall.CloseOnExec(p.kq)
p.events = p.eventbuf[0:0]
return p, nil
}
示例5: newpollster
func newpollster() (p *pollster, err error) {
p = new(pollster)
var e int
if p.kq, e = syscall.Kqueue(); e != 0 {
return nil, os.NewSyscallError("kqueue", e)
}
p.events = p.eventbuf[0:0]
return p, nil
}
示例6: NewKqueue
func NewKqueue() (*Kqueue, error) {
fd, err := syscall.Kqueue()
if err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
return &Kqueue{
Fd: fd,
}, nil
}
示例7: newkqueue
func newkqueue() (*kqueue, error) {
fd, err := syscall.Kqueue()
if err != nil {
return nil, os.NewSyscallError("kqueue", err)
}
return &kqueue{
fd: fd,
}, nil
}
示例8: NewWatcher
func NewWatcher() (IFSEventsWatcher, error) {
if fd, err := syscall.Kqueue(); fd == sysCallFailed {
return nil, os.NewSyscallError("kqueue", err)
} else {
w := &watcher{
kq: fd,
watchedByFD: make(map[int]*watchInfo),
watchedByPath: make(map[string]*watchInfo),
}
return w, nil
}
}
示例9: init
// init initializes kqueue.
func (k *kqueue) init() (err error) {
if k.fd, err = syscall.Kqueue(); err != nil {
return
}
// Creates pipe used to stop `Kevent` call by registering it,
// watching read end and writing to other end of it.
if err = syscall.Pipe(k.pipefds[:]); err != nil {
return
}
var kevn [1]syscall.Kevent_t
syscall.SetKevent(&kevn[0], k.pipefds[0], syscall.EVFILT_READ, syscall.EV_ADD)
_, err = syscall.Kevent(k.fd, kevn[:], nil, nil)
return
}
示例10: New
func New(fd int) (p *Poller, err error) {
p = &Poller{}
p.kqfd, err = syscall.Kqueue()
if p.kqfd == -1 || err != nil {
return nil, err
}
p.event = syscall.Kevent_t{
Ident: uint32(fd),
Filter: syscall.EVFILT_WRITE,
Flags: syscall.EV_ADD | syscall.EV_ENABLE | syscall.EV_ONESHOT,
Fflags: 0,
Data: 0,
Udata: nil,
}
return p, nil
}
示例11: NewWatcher
// NewWatcher creates and returns a new kevent instance using kqueue(2)
func NewWatcher() (*Watcher, error) {
fd, errno := syscall.Kqueue()
if fd == -1 {
return nil, os.NewSyscallError("kqueue", errno)
}
w := &Watcher{
kq: fd,
watches: make(map[string]int),
paths: make(map[int]string),
finfo: make(map[int]*os.FileInfo),
Event: make(chan *FileEvent),
Error: make(chan error),
done: make(chan bool, 1),
}
go w.readEvents()
return w, nil
}
示例12: NewWatcher
// NewWatcher creates and returns a new kevent instance using kqueue(2)
func NewWatcher() (*Watcher, error) {
fd, errno := syscall.Kqueue()
if fd == -1 {
return nil, os.NewSyscallError("kqueue", errno)
}
w := &Watcher{
kq: fd,
watches: make(map[string]int),
enFlags: make(map[string]uint32),
paths: make(map[int]string),
finfo: make(map[int]os.FileInfo),
fileExists: make(map[string]bool),
externalWatches: make(map[string]bool),
Events: make(chan Event),
Errors: make(chan error),
done: make(chan bool, 1),
}
go w.readEvents()
return w, nil
}
示例13: main
func main() {
flag.Parse()
args = flag.Args()
var err error
win, err = acme.New()
if err != nil {
log.Fatal(err)
}
pwd, _ := os.Getwd()
win.Name(pwd + "/+watch")
win.Ctl("clean")
win.Fprintf("tag", "Get ")
needrun <- true
go events()
go runner()
kq.fd, err = syscall.Kqueue()
if err != nil {
log.Fatal(err)
}
kq.m = make(map[string]*os.File)
kq.name = make(map[int]string)
dir, err := os.Open(".")
if err != nil {
log.Fatal(err)
}
kq.dir = dir
kadd(int(dir.Fd()))
readdir := true
for {
if readdir {
kq.dir.Seek(0, 0)
names, err := kq.dir.Readdirnames(-1)
if err != nil {
log.Fatalf("readdir: %v", err)
}
for _, name := range names {
if kq.m[name] != nil {
continue
}
f, err := os.Open(name)
if err != nil {
continue
}
kq.m[name] = f
fd := int(f.Fd())
kq.name[fd] = name
kadd(fd)
}
}
kbuf := make([]syscall.Kevent_t, 1)
var n int
for {
n, err = syscall.Kevent(kq.fd, nil, kbuf[:1], nil)
if err == syscall.EINTR {
continue
}
break
}
if err != nil {
log.Fatalf("kevent wait: %v", err)
}
ev := &kbuf[0]
if n != 1 || int(ev.Filter) != syscall.EVFILT_VNODE {
log.Fatal("kqueue phase error")
}
select {
case needrun <- true:
default:
}
fd := int(ev.Ident)
readdir = fd == int(kq.dir.Fd())
time.Sleep(100 * time.Millisecond)
kadd(fd)
}
}
示例14: createListener
// Initialize bsd implementation of the eventListener interface
func createListener() (eventListener, error) {
listener := &kqueueListener{}
kq, err := syscall.Kqueue()
listener.kq = kq
return listener, err
}