本文整理匯總了Golang中syscall.EpollCtl函數的典型用法代碼示例。如果您正苦於以下問題:Golang EpollCtl函數的具體用法?Golang EpollCtl怎麽用?Golang EpollCtl使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EpollCtl函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: epollinit
// epollinit opens an epoll file descriptor and creates a pipe which will be
// used to wake up the epoll_wait(2) function. Then, file descriptor associated
// with inotify event queue and the read end of the pipe are added to epoll set.
// Note that `fd` member must be set before this function is called.
func (i *inotify) epollinit() (err error) {
if i.epfd, err = syscall.EpollCreate1(0); err != nil {
return
}
if err = syscall.Pipe(i.pipefd); err != nil {
return
}
i.epes = []syscall.EpollEvent{
{Events: syscall.EPOLLIN, Fd: i.fd},
{Events: syscall.EPOLLIN, Fd: int32(i.pipefd[0])},
}
if err = syscall.EpollCtl(i.epfd, syscall.EPOLL_CTL_ADD, int(i.fd), &i.epes[0]); err != nil {
return
}
return syscall.EpollCtl(i.epfd, syscall.EPOLL_CTL_ADD, i.pipefd[0], &i.epes[1])
}
示例2: StopWaiting
func (p *pollster) StopWaiting(fd int, bits uint) {
events, already := p.events[fd]
if !already {
print("Epoll unexpected fd=", fd, "\n")
return
}
// If syscall.EPOLLONESHOT is not set, the wait
// is a repeating wait, so don't change it.
if events&syscall.EPOLLONESHOT == 0 {
return
}
// Disable the given bits.
// If we're still waiting for other events, modify the fd
// event in the kernel. Otherwise, delete it.
events &= ^uint32(bits)
if int32(events)&^syscall.EPOLLONESHOT != 0 {
var ev syscall.EpollEvent
ev.Fd = int32(fd)
ev.Events = events
if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_MOD, fd, &ev); e != 0 {
print("Epoll modify fd=", fd, ": ", os.Errno(e).String(), "\n")
}
p.events[fd] = events
} else {
if e := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_DEL, fd, nil); e != 0 {
print("Epoll delete fd=", fd, ": ", os.Errno(e).String(), "\n")
}
p.events[fd] = 0, false
}
}
示例3: StopWaiting
func (p *pollster) StopWaiting(fd int, bits uint) {
// pollServer is locked.
events, already := p.events[fd]
if !already {
// The fd returned by the kernel may have been
// cancelled already; return silently.
return
}
// If syscall.EPOLLONESHOT is not set, the wait
// is a repeating wait, so don't change it.
if events&syscall.EPOLLONESHOT == 0 {
return
}
// Disable the given bits.
// If we're still waiting for other events, modify the fd
// event in the kernel. Otherwise, delete it.
events &= ^uint32(bits)
if int32(events)&^syscall.EPOLLONESHOT != 0 {
p.ctlEvent.Fd = int32(fd)
p.ctlEvent.Events = events
if err := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_MOD, fd, &p.ctlEvent); err != nil {
print("Epoll modify fd=", fd, ": ", err.Error(), "\n")
}
p.events[fd] = events
} else {
if err := syscall.EpollCtl(p.epfd, syscall.EPOLL_CTL_DEL, fd, nil); err != nil {
print("Epoll delete fd=", fd, ": ", err.Error(), "\n")
}
delete(p.events, fd)
}
}
示例4: ProxyNetAccept
func (io *NetIOManager) ProxyNetAccept(serverinfo syscall.Sockaddr) (sa syscall.Sockaddr, err error) {
var clientfd, serverfd int
// accpet mongodb client connection request
clientfd, clientinfo, err := syscall.Accept(io.proxy_server_fd)
if err != nil {
goto ClientError
}
err = syscall.SetNonblock(clientfd, true)
if err != nil {
goto ClientCleanup
}
err = syscall.EpollCtl(io.epoll_fd, syscall.EPOLL_CTL_ADD, clientfd,
&syscall.EpollEvent{Events: syscall.EPOLLIN | syscall.EPOLLOUT |
syscall.EPOLLRDHUP, Fd: int32(clientfd)})
if err != nil {
goto ClientCleanup
}
// establish connection with mongodb server
serverfd, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM,
syscall.IPPROTO_TCP)
if err != nil {
goto ServerError
}
err = syscall.Connect(serverfd, serverinfo)
if err != nil {
goto ServerCleanup
}
err = syscall.SetNonblock(serverfd, true)
if err != nil {
goto ServerCleanup
}
err = syscall.EpollCtl(io.epoll_fd, syscall.EPOLL_CTL_ADD, serverfd,
&syscall.EpollEvent{Events: syscall.EPOLLIN | syscall.EPOLLOUT |
syscall.EPOLLRDHUP, Fd: int32(serverfd)})
if err != nil {
goto ServerCleanup
}
// now proxy server becomes a bridge between client <-> server
add_sock_peer(io, clientfd, clientinfo, serverfd, serverinfo)
return clientinfo, nil
ServerCleanup:
syscall.Close(serverfd)
ServerError:
syscall.EpollCtl(io.epoll_fd, syscall.EPOLL_CTL_DEL, clientfd,
&syscall.EpollEvent{Events: syscall.EPOLLIN | syscall.EPOLLOUT |
syscall.EPOLLRDHUP, Fd: int32(clientfd)})
ClientCleanup:
syscall.Close(clientfd)
ClientError:
return nil, err
}
示例5: closeUnlocked
func (fd *FD) closeUnlocked() error {
// Caller MUST already hold the C lock. Take the both R and W
// locks, to exclude Read and Write operations from accessing
// a closed sysfd.
fd.r.cond.L.Lock()
fd.w.cond.L.Lock()
fd.closed = true
// ev is not used by EpollCtl/DEL. Just don't pass a nil
// pointer.
var ev syscall.EpollEvent
err := syscall.EpollCtl(epfd, syscall.EPOLL_CTL_DEL, fd.sysfd, &ev)
if err != nil {
log.Printf("poller: EpollCtl/DEL (fd=%d, sysfd=%d): %s",
fd.id, fd.sysfd, err.Error())
}
if fd.r.timer != nil {
fd.r.timer.Stop()
}
if fd.w.timer != nil {
fd.w.timer.Stop()
}
fdM.DelFD(fd.id)
err = syscall.Close(fd.sysfd)
// Wake up everybody waiting on the FD.
fd.r.cond.Broadcast()
fd.w.cond.Broadcast()
debugf("FD %03d: CL: close(sysfd=%d)", fd.id, fd.sysfd)
fd.w.cond.L.Unlock()
fd.r.cond.L.Unlock()
return err
}
示例6: AddFD
func (p *pollster) AddFD(fd int, mode int, repeat bool) (bool, error) {
// pollServer is locked.
var already bool
p.ctlEvent.Fd = int32(fd)
p.ctlEvent.Events, already = p.events[fd]
if !repeat {
p.ctlEvent.Events |= syscall.EPOLLONESHOT
}
if mode == 'r' {
p.ctlEvent.Events |= readFlags
} else {
p.ctlEvent.Events |= writeFlags
}
var op int
if already {
op = syscall.EPOLL_CTL_MOD
} else {
op = syscall.EPOLL_CTL_ADD
}
if e := syscall.EpollCtl(p.epfd, op, fd, &p.ctlEvent); e != nil {
return false, os.NewSyscallError("epoll_ctl", e)
}
p.events[fd] = p.ctlEvent.Events
return false, nil
}
示例7: AddFD
func (p *pollster) AddFD(fd int, mode int, repeat bool) os.Error {
var ev syscall.EpollEvent
var already bool
ev.Fd = int32(fd)
ev.Events, already = p.events[fd]
if !repeat {
ev.Events |= syscall.EPOLLONESHOT
}
if mode == 'r' {
ev.Events |= readFlags
} else {
ev.Events |= writeFlags
}
var op int
if already {
op = syscall.EPOLL_CTL_MOD
} else {
op = syscall.EPOLL_CTL_ADD
}
if e := syscall.EpollCtl(p.epfd, op, fd, &ev); e != 0 {
return os.NewSyscallError("epoll_ctl", e)
}
p.events[fd] = ev.Events
return nil
}
示例8: ProxyNetListen
func (io *NetIOManager) ProxyNetListen(sa syscall.Sockaddr) error {
serverfd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM,
syscall.IPPROTO_TCP)
if err != nil {
goto Error
}
err = syscall.Bind(serverfd, sa)
if err != nil {
goto Cleanup
}
err = syscall.Listen(serverfd, io.max_backlog)
if err != nil {
goto Cleanup
}
err = syscall.EpollCtl(io.epoll_fd, syscall.EPOLL_CTL_ADD, serverfd,
&syscall.EpollEvent{Events: syscall.EPOLLIN, Fd: int32(serverfd)})
if err != nil {
goto Cleanup
}
io.proxy_server_fd = serverfd
return nil
Cleanup:
syscall.Close(serverfd)
Error:
return err
}
示例9: registerInterrupt
func registerInterrupt(pin *digitalPin, handler func(embd.DigitalPin)) error {
l := getEpollListenerInstance()
pinFd := int(pin.val.Fd())
l.mu.Lock()
defer l.mu.Unlock()
if _, ok := l.interruptablePins[pinFd]; ok {
return ErrorPinAlreadyRegistered
}
var event syscall.EpollEvent
event.Events = syscall.EPOLLIN | (syscall.EPOLLET & 0xffffffff) | syscall.EPOLLPRI
if err := syscall.SetNonblock(pinFd, true); err != nil {
return err
}
event.Fd = int32(pinFd)
if err := syscall.EpollCtl(l.fd, syscall.EPOLL_CTL_ADD, pinFd, &event); err != nil {
return err
}
l.interruptablePins[pinFd] = &interrupt{pin: pin, handler: handler}
return nil
}
示例10: newFD
func newFD(sysfd int) (*FD, error) {
// Set sysfd to non-blocking mode
err := syscall.SetNonblock(sysfd, true)
if err != nil {
debugf("FD xxx: NF: sysfd=%d, err=%v", sysfd, err)
return nil, err
}
// Initialize FD
fd := &FD{sysfd: sysfd}
fd.id = fdM.GetID()
fd.r.cond = sync.NewCond(&fd.r.mu)
fd.w.cond = sync.NewCond(&fd.w.mu)
// Add to Epoll set. We may imediatelly start receiving events
// after this. They will be dropped since the FD is not yet in
// fdMap. It's ok. Nobody is waiting on this FD yet, anyway.
ev := syscall.EpollEvent{
Events: syscall.EPOLLIN |
syscall.EPOLLOUT |
syscall.EPOLLRDHUP |
(syscall.EPOLLET & 0xffffffff),
Fd: int32(fd.id)}
err = syscall.EpollCtl(epfd, syscall.EPOLL_CTL_ADD, fd.sysfd, &ev)
if err != nil {
debugf("FD %03d: NF: sysfd=%d, err=%v", fd.id, fd.sysfd, err)
return nil, err
}
// Add to fdMap
fdM.AddFD(fd)
debugf("FD %03d: NF: sysfd=%d", fd.id, fd.sysfd)
return fd, nil
}
示例11: BeginWatch
func (p *pin) BeginWatch(edge Edge, callback IRQEvent) error {
p.SetMode(ModeInput)
if err := write([]byte(edge), p.edgePath); err != nil {
return err
}
var event syscall.EpollEvent
event.Events = syscall.EPOLLIN | (syscall.EPOLLET & 0xffffffff) | syscall.EPOLLPRI
fd := int(p.valueFile.Fd())
p.callback = callback
watchEventCallbacks[fd] = p
if err := syscall.SetNonblock(fd, true); err != nil {
return err
}
event.Fd = int32(fd)
if err := syscall.EpollCtl(epollFD, syscall.EPOLL_CTL_ADD, fd, &event); err != nil {
return err
}
return nil
}
示例12: DisableEdgeDetection
func (gpio *GPIO) DisableEdgeDetection() {
epollFd := gpio.epollFd.Swap(0)
if epollFd != 0 {
syscall.EpollCtl(epollFd, syscall.EPOLL_CTL_DEL, int(gpio.valueFile.Fd()), new(syscall.EpollEvent))
syscall.Close(epollFd)
}
gpio.setEdge(EDGE_NONE)
}
示例13: sock_close
func sock_close(io *NetIOManager, fd int) {
syscall.EpollCtl(io.epoll_fd, syscall.EPOLL_CTL_DEL, fd,
&syscall.EpollEvent{Events: syscall.EPOLLIN | syscall.EPOLLOUT |
syscall.EPOLLRDHUP, Fd: int32(fd)})
syscall.Close(fd)
delete(io.pending_output_skbs, fd)
delete(io.io_socket_peers, fd)
}
示例14: AddFD
func (ep *EPoll) AddFD(fd int, events uint32) error {
ev := syscall.EpollEvent{
Events: events,
Fd: int32(fd),
}
return syscall.EpollCtl(ep.fd, syscall.EPOLL_CTL_ADD, fd, &ev)
}
示例15: Add
// Add registers a socket for sending and/or receiving. The caller can't
// access the socket directly after this. The send channel (if any) should be
// closed by the caller.
func (io *IO) Add(s *zmq.Socket, send <-chan Data, recv chan<- Data) (err error) {
fd, err := s.GetFd()
if err != nil {
return
}
w := newWorker()
io.lock.Lock()
io.workers[int32(fd)] = w
io.lock.Unlock()
defer func() {
if err != nil {
io.lock.Lock()
delete(io.workers, int32(fd))
io.lock.Unlock()
}
}()
e := &syscall.EpollEvent{
Events: syscall.EPOLLIN | syscall.EPOLLET&0xffffffff,
Fd: int32(fd),
}
if err = syscall.EpollCtl(io.epollFd, syscall.EPOLL_CTL_ADD, fd, e); err != nil {
return
}
state, err := s.GetEvents()
if err != nil {
syscall.EpollCtl(io.epollFd, syscall.EPOLL_CTL_DEL, fd, nil)
return
}
go func() {
defer s.Close()
defer syscall.EpollCtl(io.epollFd, syscall.EPOLL_CTL_DEL, fd, nil)
w.socketLoop(s, send, recv, state)
}()
return
}