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


Golang syscall.Kqueue函数代码示例

本文整理汇总了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
}
开发者ID:noonat,项目名称:runit,代码行数:8,代码来源:kqueue.go

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

示例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
}
开发者ID:straywithsmile,项目名称:go_src,代码行数:8,代码来源:poll.go

示例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
}
开发者ID:pkdevboxy,项目名称:appscale,代码行数:9,代码来源:fd_bsd.go

示例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
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:9,代码来源:fd_openbsd.go

示例6: NewKqueue

func NewKqueue() (*Kqueue, error) {
	fd, err := syscall.Kqueue()
	if err != nil {
		return nil, os.NewSyscallError("kqueue", err)
	}
	return &Kqueue{
		Fd: fd,
	}, nil
}
开发者ID:jonsen,项目名称:kqueue,代码行数:9,代码来源:kqueue.go

示例7: newkqueue

func newkqueue() (*kqueue, error) {
	fd, err := syscall.Kqueue()
	if err != nil {
		return nil, os.NewSyscallError("kqueue", err)
	}
	return &kqueue{
		fd: fd,
	}, nil
}
开发者ID:davecheney,项目名称:fswatch,代码行数:9,代码来源:kqueue.go

示例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
	}
}
开发者ID:darvik80,项目名称:monitor,代码行数:13,代码来源:fsevents_darwin.go

示例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
}
开发者ID:kaocs,项目名称:notify,代码行数:15,代码来源:watcher_kqueue.go

示例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
}
开发者ID:andradeandrey,项目名称:go-ipfs,代码行数:18,代码来源:poll_darwin_386.go

示例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
}
开发者ID:bjconlan,项目名称:go-livereload,代码行数:19,代码来源:fsnotify_bsd.go

示例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
}
开发者ID:jackc,项目名称:react2fs-deb,代码行数:22,代码来源:fsnotify_bsd.go

示例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)
	}
}
开发者ID:rsc,项目名称:rsc,代码行数:82,代码来源:main.go

示例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
}
开发者ID:ChongFeng,项目名称:beats,代码行数:7,代码来源:psnotify_bsd.go


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