Skip to content

Commit

Permalink
feat: epoll managered by runtime netpoller
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Mar 13, 2024
1 parent bb9c3f7 commit b403b36
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cloudwego/netpoll

go 1.15
go 1.18

require (
github.com/bytedance/gopkg v0.0.0-20220413063733-65bf48ffb3a7
Expand Down
6 changes: 5 additions & 1 deletion poll_default_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ import (
"unsafe"
)

func openPollFile() (int, error) {
return syscall.Kqueue()
}

func openPoll() (Poll, error) {
return openDefaultPoll()
}

func openDefaultPoll() (*defaultPoll, error) {
l := new(defaultPoll)
p, err := syscall.Kqueue()
p, err := openPollFile()
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions poll_default_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import (
"unsafe"
)

func openPollFile() (int, error) {
return EpollCreate(0)
}

func openPoll() (Poll, error) {
return openDefaultPoll()
}
Expand Down
11 changes: 11 additions & 0 deletions runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package netpoll

import (
_ "unsafe"
)

//go:linkname pollOpen internal/poll.runtime_pollOpen
func pollOpen(fd uintptr) (pd uintptr, errno int)

//go:linkname pollWait internal/poll.runtime_pollWait
func pollWait(pd uintptr, mode int) (errno int)
18 changes: 18 additions & 0 deletions runtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package netpoll

import (
"testing"
)

func TestRuntimeNetpoller(t *testing.T) {
pfd, err := openPollFile()
MustNil(t, err)

pd, errno := pollOpen(uintptr(pfd))
Assert(t, errno == 0, errno)

errno = pollWait(pd, 'r')
Assert(t, errno == 0, errno)

_ = pfd
}

0 comments on commit b403b36

Please sign in to comment.