Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #241 from Pennyzct/epoll
Browse files Browse the repository at this point in the history
channel: Support Epoll on Arm64
  • Loading branch information
jodh-intel authored May 16, 2018
2 parents e444fe2 + 7b47559 commit d4580c7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"

"github.com/hashicorp/yamux"
"github.com/mdlayher/vsock"
Expand Down Expand Up @@ -94,32 +93,32 @@ func (c *serialChannel) setup() error {
}

func (c *serialChannel) wait() error {
var event syscall.EpollEvent
var events [1]syscall.EpollEvent
var event unix.EpollEvent
var events [1]unix.EpollEvent

fd := c.serialConn.Fd()
if fd <= 0 {
return fmt.Errorf("serial port IO closed")
}

epfd, err := syscall.EpollCreate1(syscall.EPOLL_CLOEXEC)
epfd, err := unix.EpollCreate1(unix.EPOLL_CLOEXEC)
if err != nil {
return err
}
defer syscall.Close(epfd)
defer unix.Close(epfd)

// EPOLLOUT: Writable when there is a connection
// EPOLLET: Edge trigger as EPOLLHUP is always on when there is no connection
// 0xffffffff: EPOLLET is negative and cannot fit in uint32 in golang
event.Events = syscall.EPOLLOUT | syscall.EPOLLET&0xffffffff
event.Events = unix.EPOLLOUT | unix.EPOLLET&0xffffffff
event.Fd = int32(fd)
if err = syscall.EpollCtl(epfd, syscall.EPOLL_CTL_ADD, int(fd), &event); err != nil {
if err = unix.EpollCtl(epfd, unix.EPOLL_CTL_ADD, int(fd), &event); err != nil {
return err
}
defer syscall.EpollCtl(epfd, syscall.EPOLL_CTL_DEL, int(fd), nil)
defer unix.EpollCtl(epfd, unix.EPOLL_CTL_DEL, int(fd), nil)

for {
nev, err := syscall.EpollWait(epfd, events[:], -1)
nev, err := unix.EpollWait(epfd, events[:], -1)
if err != nil {
return err
}
Expand All @@ -128,13 +127,13 @@ func (c *serialChannel) wait() error {
ev := events[i]
if ev.Fd == int32(fd) {
agentLog.WithField("events", ev.Events).Debug("New serial channel event")
if ev.Events&syscall.EPOLLOUT != 0 {
if ev.Events&unix.EPOLLOUT != 0 {
return nil
}
if ev.Events&syscall.EPOLLERR != 0 {
if ev.Events&unix.EPOLLERR != 0 {
return fmt.Errorf("serial port IO failure")
}
if ev.Events&syscall.EPOLLHUP != 0 {
if ev.Events&unix.EPOLLHUP != 0 {
continue
}
}
Expand Down

0 comments on commit d4580c7

Please sign in to comment.