aboutsummaryrefslogtreecommitdiff
path: root/lib/net/poll.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2019-11-01 17:42:29 +0700
committerShulhan <m.shulhan@gmail.com>2019-11-01 17:42:29 +0700
commit090518aff64907a8df0d09e4e909cbd6f4f1f985 (patch)
tree8f87ed42e99aa01b3ed96a5199885de7a5ce84ae /lib/net/poll.go
parenta2157aeacc23fcc2581681ffaed2609ae0365c0b (diff)
downloadpakakeh.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.go39
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)
+}