当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Kevent函数代码示例

本文整理汇总了Golang中syscall.Kevent函数的典型用法代码示例。如果您正苦于以下问题:Golang Kevent函数的具体用法?Golang Kevent怎么用?Golang Kevent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Kevent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Unwatch

// Unwatch implements trigger.
func (k *kq) Unwatch(w *watched) (err error) {
	var kevn [1]syscall.Kevent_t
	syscall.SetKevent(&kevn[0], w.fd, syscall.EVFILT_VNODE, syscall.EV_DELETE)

	_, err = syscall.Kevent(k.fd, kevn[:], nil, nil)
	return
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:8,代码来源:watcher_kqueue.go

示例2: singlewatch

// watch starts to watch given p file/directory.
func (k *kqueue) singlewatch(p string, e Event, direct bool,
	fi os.FileInfo) error {
	w, ok := k.pthLkp[p]
	if !ok {
		fd, err := syscall.Open(p, syscall.O_NONBLOCK|syscall.O_RDONLY, 0)
		if err != nil {
			return err
		}
		w = &watched{fd: fd, p: p, fi: fi}
	}
	if direct {
		w.eDir |= e
	} else {
		w.eNonDir |= e
	}
	var kevn [1]syscall.Kevent_t
	syscall.SetKevent(&kevn[0], w.fd, syscall.EVFILT_VNODE,
		syscall.EV_ADD|syscall.EV_CLEAR)
	kevn[0].Fflags = encode(w.eDir | w.eNonDir)
	if _, err := syscall.Kevent(k.fd, kevn[:], nil, nil); err != nil {
		return err
	}
	if !ok {
		k.idLkp[w.fd], k.pthLkp[w.p] = w, w
		return nil
	}
	return errAlreadyWatched
}
开发者ID:kaocs,项目名称:notify,代码行数:29,代码来源:watcher_kqueue.go

示例3: doDel

func (this *watcher) doDel(path string) error {
	info, found := this.watchedByPath[path]
	if !found {
		return errors.Newf("can't remove non-existent kevent watch for: %s", path)
	}

	var kbuf [1]syscall.Kevent_t
	watchEntry := &kbuf[0]
	syscall.SetKevent(watchEntry, info.fd, syscall.EVFILT_VNODE, syscall.EV_DELETE)
	entryFlags := watchEntry.Flags
	success, errno := syscall.Kevent(this.kq, kbuf[:], nil, nil)
	if success == sysCallFailed {
		return os.NewSyscallError("kevent_rm_watch", errno)
	} else if entryFlags&syscall.EV_ERROR == syscall.EV_ERROR {
		return errors.New("kevent rm error")
	}
	syscall.Close(info.fd)

	//Remove childs if it's directory
	for _, child := range info.childes {
		this.doDel(child)
	}

	delete(this.watchedByPath, path)
	delete(this.watchedByFD, info.fd)

	return nil
}
开发者ID:darvik80,项目名称:monitor,代码行数:28,代码来源:fsevents_darwin.go

示例4: WaitFD

func (p *pollster) WaitFD(s *pollServer, nsec int64) (fd int, mode int, err error) {
	var t *syscall.Timespec
	for len(p.events) == 0 {
		if nsec > 0 {
			if t == nil {
				t = new(syscall.Timespec)
			}
			*t = syscall.NsecToTimespec(nsec)
		}

		s.Unlock()
		n, err := syscall.Kevent(p.kq, nil, p.eventbuf[:], t)
		s.Lock()

		if err != nil {
			if err == syscall.EINTR {
				continue
			}
			return -1, 0, os.NewSyscallError("kevent", err)
		}
		if n == 0 {
			return -1, 0, nil
		}
		p.events = p.eventbuf[:n]
	}
	ev := &p.events[0]
	p.events = p.events[1:]
	fd = int(ev.Ident)
	if ev.Filter == syscall.EVFILT_READ {
		mode = 'r'
	} else {
		mode = 'w'
	}
	return fd, mode, nil
}
开发者ID:pkdevboxy,项目名称:appscale,代码行数:35,代码来源:fd_bsd.go

示例5: 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()
		}
	}
}
开发者ID:jayvansantos,项目名称:eyenotify,代码行数:30,代码来源:eyenotify_darwin.go

示例6: Kevent

func (p *pollster) Kevent(nsec int64) (result int, events []net_event, err error) {
	var t *syscall.Timespec
	if nsec > 0 {
		if t == nil {
			t = new(syscall.Timespec)
		}
		*t = syscall.NsecToTimespec(nsec)
	}
	n, err := syscall.Kevent(p.kq, nil, p.eventbuf[:], t)

	if err != nil {
		if err == syscall.EINTR {
			return 0, nil, nil
		} else {
			return -1, nil, os.NewSyscallError("kevent", err)
		}
	}
	if n == 0 {
		return -2, nil, nil
	}
	events = make([]net_event, n)
	for i, ev := range p.eventbuf {
		events[i].fd = int(ev.Ident)
		events[i].data = int(ev.Data)
		if ev.Filter == syscall.EVFILT_READ {
			events[i].mode = 'r'
		} else {
			events[i].mode = 'w'
		}
	}
	return n, events, nil
}
开发者ID:straywithsmile,项目名称:go_src,代码行数:32,代码来源:poll.go

示例7: readEvents

// Poll the kqueue file descriptor and dispatch to the Event channels
func (w *Watcher) readEvents() {
	listener, _ := w.listener.(*kqueueListener)
	events := make([]syscall.Kevent_t, 10)

	for {
		if w.isDone() {
			return
		}

		n, err := syscall.Kevent(listener.kq, nil, events, nil)
		if err != nil {
			w.Error <- err
			continue
		}

		for _, ev := range events[:n] {
			pid := int(ev.Ident)

			switch ev.Fflags {
			case syscall.NOTE_FORK:
				w.Fork <- &ProcEventFork{ParentPid: pid}
			case syscall.NOTE_EXEC:
				w.Exec <- &ProcEventExec{Pid: pid}
			case syscall.NOTE_EXIT:
				w.RemoveWatch(pid)
				w.Exit <- &ProcEventExit{Pid: pid}
			}
		}
	}
}
开发者ID:ChongFeng,项目名称:beats,代码行数:31,代码来源:psnotify_bsd.go

示例8: WaitFD

func (p *pollster) WaitFD(nsec int64) (fd int, mode int, err os.Error) {
	var t *syscall.Timespec
	for len(p.events) == 0 {
		if nsec > 0 {
			if t == nil {
				t = new(syscall.Timespec)
			}
			*t = syscall.NsecToTimespec(nsec)
		}
		nn, e := syscall.Kevent(p.kq, nil, &p.eventbuf, t)
		if e != 0 {
			if e == syscall.EINTR {
				continue
			}
			return -1, 0, os.NewSyscallError("kevent", e)
		}
		if nn == 0 {
			return -1, 0, nil
		}
		p.events = p.eventbuf[0:nn]
	}
	ev := &p.events[0]
	p.events = p.events[1:len(p.events)]
	fd = int(ev.Ident)
	if ev.Filter == syscall.EVFILT_READ {
		mode = 'r'
	} else {
		mode = 'w'
	}
	return fd, mode, nil
}
开发者ID:8l,项目名称:go-learn,代码行数:31,代码来源:fd_darwin.go

示例9: Wait

func (k *Kqueue) Wait(buf []syscall.Kevent_t) (int, error) {
	n, err := syscall.Kevent(k.Fd, nil, buf, nil)
	if err != nil {
		return 0, os.NewSyscallError("kevent", err)
	}
	return n, nil
}
开发者ID:jonsen,项目名称:kqueue,代码行数:7,代码来源:kqueue.go

示例10: AddFD

func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
	var kmode int
	if mode == 'r' {
		kmode = syscall.EVFILT_READ
	} else {
		kmode = syscall.EVFILT_WRITE
	}
	var events [1]syscall.Kevent_t
	ev := &events[0]
	// EV_ADD - add event to kqueue list
	// EV_RECEIPT - generate fake EV_ERROR as result of add,
	//	rather than waiting for real event
	// EV_ONESHOT - delete the event the first time it triggers
	flags := syscall.EV_ADD | syscall.EV_RECEIPT
	if !repeat {
		flags |= syscall.EV_ONESHOT
	}
	syscall.SetKevent(ev, fd, kmode, flags)

	n, e := syscall.Kevent(p.kq, &events, &events, nil)
	if e != 0 {
		return os.NewSyscallError("kevent", e)
	}
	if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
		return os.ErrorString("kqueue phase error")
	}
	if ev.Data != 0 {
		return os.Errno(int(ev.Data))
	}
	return nil
}
开发者ID:8l,项目名称:go-learn,代码行数:31,代码来源:fd_darwin.go

示例11: read

// read retrieves pending events, or waits until an event occurs.
// A timeout of nil blocks indefinitely, while 0 polls the queue.
func read(kq int, events []syscall.Kevent_t, timeout *syscall.Timespec) ([]syscall.Kevent_t, error) {
	n, err := syscall.Kevent(kq, nil, events, timeout)
	if err != nil {
		return nil, err
	}
	return events[0:n], nil
}
开发者ID:noonat,项目名称:runit,代码行数:9,代码来源:kqueue.go

示例12: addWatch

// AddWatch adds path to the watched file set.
// The flags are interpreted as described in kevent(2).
func (w *Watcher) addWatch(path string, flags uint32) error {
	if w.isClosed {
		return errors.New("kevent instance already closed")
	}

	watchEntry := &w.kbuf[0]
	watchEntry.Fflags = flags

	watchfd, found := w.watches[path]
	if !found {
		fd, errno := syscall.Open(path, syscall.O_NONBLOCK|syscall.O_RDONLY, 0700)
		if fd == -1 {
			return &os.PathError{"kevent_add_watch", path, errno}
		}
		watchfd = fd

		w.watches[path] = watchfd
		w.paths[watchfd] = path

		fi, _ := os.Stat(path)
		w.finfo[watchfd] = &fi
	}
	syscall.SetKevent(watchEntry, watchfd, syscall.EVFILT_VNODE, syscall.EV_ADD|syscall.EV_CLEAR)

	wd, errno := syscall.Kevent(w.kq, w.kbuf[:], nil, nil)
	if wd == -1 {
		return &os.PathError{"kevent_add_watch", path, errno}
	} else if (watchEntry.Flags & syscall.EV_ERROR) == syscall.EV_ERROR {
		return &os.PathError{"kevent_add_watch", path, errors.New(fmt.Sprintf("%v", watchEntry.Data))}
	}

	return nil
}
开发者ID:bjconlan,项目名称:go-livereload,代码行数:35,代码来源:fsnotify_bsd.go

示例13: singleunwatch

// unwatch stops watching p file/directory.
func (k *kqueue) singleunwatch(p string, direct bool) error {
	w := k.pthLkp[p]
	if w == nil {
		return errNotWatched
	}
	if direct {
		w.eDir = 0
	} else {
		w.eNonDir = 0
	}
	var kevn [1]syscall.Kevent_t
	syscall.SetKevent(&kevn[0], w.fd, syscall.EVFILT_VNODE, syscall.EV_DELETE)
	if _, err := syscall.Kevent(k.fd, kevn[:], nil, nil); err != nil {
		return err
	}
	if w.eNonDir&w.eDir != 0 {
		if err := k.singlewatch(p, w.eNonDir|w.eDir, w.eNonDir == 0,
			w.fi); err != nil {
			return err
		}
	} else {
		k.del(*w)
	}
	return nil
}
开发者ID:kaocs,项目名称:notify,代码行数:26,代码来源:watcher_kqueue.go

示例14: removeWatch

// RemoveWatch removes path from the watched file set.
func (w *Watcher) removeWatch(path string) error {
	w.wmut.Lock()
	watchfd, ok := w.watches[path]
	w.wmut.Unlock()
	if !ok {
		return errors.New(fmt.Sprintf("can't remove non-existent kevent watch for: %s", path))
	}
	w.bufmut.Lock()
	defer w.bufmut.Unlock()
	watchEntry := &w.kbuf[0]
	syscall.SetKevent(watchEntry, watchfd, syscall.EVFILT_VNODE, syscall.EV_DELETE)
	success, errno := syscall.Kevent(w.kq, w.kbuf[:], nil, nil)
	if success == -1 {
		return os.NewSyscallError("kevent_rm_watch", errno)
	} else if (watchEntry.Flags & syscall.EV_ERROR) == syscall.EV_ERROR {
		return errors.New("kevent rm error")
	}
	syscall.Close(watchfd)
	w.wmut.Lock()
	delete(w.watches, path)
	w.wmut.Unlock()
	w.enmut.Lock()
	delete(w.enFlags, path)
	w.enmut.Unlock()
	w.pmut.Lock()
	delete(w.paths, watchfd)
	delete(w.finfo, watchfd)
	w.pmut.Unlock()
	return nil
}
开发者ID:ChrisBuchholz,项目名称:fsnotify,代码行数:31,代码来源:fsnotify_bsd.go

示例15: AddFD

// First return value is whether the pollServer should be woken up.
// This version always returns false.
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
	// pollServer is locked.

	var kmode int
	if mode == 'r' {
		kmode = syscall.EVFILT_READ
	} else {
		kmode = syscall.EVFILT_WRITE
	}
	ev := &p.kbuf[0]
	// EV_ADD - add event to kqueue list
	// EV_ONESHOT - delete the event the first time it triggers
	flags := syscall.EV_ADD
	if !repeat {
		flags |= syscall.EV_ONESHOT
	}
	syscall.SetKevent(ev, fd, kmode, flags)

	n, err := syscall.Kevent(p.kq, p.kbuf[:], nil, nil)
	if err != nil {
		return false, os.NewSyscallError("kevent", err)
	}
	if n != 1 || (ev.Flags&syscall.EV_ERROR) == 0 || int(ev.Ident) != fd || int(ev.Filter) != kmode {
		return false, os.NewSyscallError("kqueue phase error", err)
	}
	if ev.Data != 0 {
		return false, syscall.Errno(int(ev.Data))
	}
	return false, nil
}
开发者ID:pkdevboxy,项目名称:appscale,代码行数:32,代码来源:fd_bsd.go


注:本文中的syscall.Kevent函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。