diff options
| author | Shulhan <m.shulhan@gmail.com> | 2019-11-01 17:42:29 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2019-11-01 17:42:29 +0700 |
| commit | 090518aff64907a8df0d09e4e909cbd6f4f1f985 (patch) | |
| tree | 8f87ed42e99aa01b3ed96a5199885de7a5ce84ae /lib/net/poll.go | |
| parent | a2157aeacc23fcc2581681ffaed2609ae0365c0b (diff) | |
| download | pakakeh.go-090518aff64907a8df0d09e4e909cbd6f4f1f985.tar.xz | |
net: implement network polling using epoll and kqueue
This is the first implementation of (almost) generic polling.
The Poll currently only support the Read events from now, because the
most common use case is for handling multiple socket without using
goroutines.
Diffstat (limited to 'lib/net/poll.go')
| -rw-r--r-- | lib/net/poll.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/net/poll.go b/lib/net/poll.go new file mode 100644 index 00000000..ec5369b2 --- /dev/null +++ b/lib/net/poll.go @@ -0,0 +1,39 @@ +package net + +const ( + maxQueue = 128 +) + +// +// Poll represent an interface to network polling. +// +type Poll interface { + // + // Close the poll. + // + Close() + + // + // RegisterRead add the file descriptor to read poll. + // + RegisterRead(fd int) (err error) + + // + // ReregisterRead register the file descriptor back to events. + // This method must be used on Linux after calling WaitRead. + // + // See https://idea.popcount.org/2017-02-20-epoll-is-fundamentally-broken-12/ + // + ReregisterRead(idx, fd int) + + // + // UnregisterRead remove file descriptor from the poll. + // + UnregisterRead(fd int) (err error) + + // + // WaitRead wait for read event received and return list of file + // descriptor that are ready for reading. + // + WaitRead() (fds []int, err error) +} |
