Skip to content

Commit

Permalink
Ensure poller events do not overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiu128 committed Apr 15, 2024
1 parent e23717d commit 5ba3c3d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/poll_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package internal

import (
"errors"
"fmt"
"io"
"sync"
"sync/atomic"
Expand All @@ -23,6 +24,17 @@ const (
PollerWriteEvent = -PollerEvent(syscall.EVFILT_WRITE)
)

func init() {
// The read and write events are used to set/unset bits in a Slot's event mask. We dispatch the read/write handler
// based on this event mask, so we must ensure they don't overlap.
if PollerReadEvent|PollerWriteEvent == PollerReadEvent || PollerReadEvent|PollerWriteEvent == PollerWriteEvent {
panic(fmt.Sprintf(
"PollerReadEvent=%d and PollerWriteEvent=%d overlap",
PollerReadEvent, PollerWriteEvent,
))
}
}

var _ Poller = &poller{}

type poller struct {
Expand Down
12 changes: 12 additions & 0 deletions internal/poll_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package internal

import (
"errors"
"fmt"
"io"
"os"
"sync"
Expand All @@ -21,6 +22,17 @@ const (
PollerWriteEvent = PollerEvent(syscall.EPOLLOUT)
)

func init() {
// The read and write events are used to set/unset bits in a Slot's event mask. We dispatch the read/write handler
// based on this event mask, so we must ensure they don't overlap.
if PollerReadEvent|PollerWriteEvent == PollerReadEvent || PollerReadEvent|PollerWriteEvent == PollerWriteEvent {
panic(fmt.Sprintf(
"PollerReadEvent=%d and PollerWriteEvent=%d overlap",
PollerReadEvent, PollerWriteEvent,
))
}
}

type Event struct {
Mask uint32
Data [8]byte
Expand Down

0 comments on commit 5ba3c3d

Please sign in to comment.