Skip to content

Commit

Permalink
check invalid event
Browse files Browse the repository at this point in the history
  • Loading branch information
pilot committed Aug 16, 2023
1 parent e0ad047 commit 03c93e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
ErrBadFileDescriptor = syscall.EBADF
ErrEventExists = errors.New("event exists")
ErrEventNotExists = errors.New("event does not exist")
ErrEventInvalid = errors.New("event invalid")
)

func temporaryErr(err error) bool {
Expand Down
12 changes: 8 additions & 4 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const (
EvClosed = 1 << iota

// EvPersist is persistent option. If not set, the event will be deleted after it is triggered.
EvPersist = 020
EvPersist = 040
// EvET is edge-triggered behavior option.
EvET = 040
EvET = 0100

// EvListInserted is the flag to indicate the event is in the event list.
EvListInserted = 0x01
Expand Down Expand Up @@ -139,11 +139,15 @@ func NewBase() (*EventBase, error) {
// Timeout is the timeout of the event. Default is 0, which means no timeout.
// But if EvTimeout is set in the event, the timeout is required.
func (bs *EventBase) AddEvent(ev *Event, timeout time.Duration) error {
if ev.events&(EvRead|EvWrite|EvClosed|EvSignal|EvTimeout) == 0 {
return ErrEventInvalid
}

if ev.flags&EvListInserted != 0 {
return ErrEventExists
}

if ev.events&(EvRead|EvWrite|EvSignal) != 0 {
if ev.events&(EvRead|EvWrite|EvClosed|EvSignal) != 0 {
if err := bs.poller.add(ev); err != nil {
return err
}
Expand Down Expand Up @@ -174,7 +178,7 @@ func (bs *EventBase) DelEvent(ev *Event) error {
bs.eventQueueRemove(ev, EvListActive)
}

if ev.events&(EvRead|EvWrite|EvSignal) != 0 {
if ev.events&(EvRead|EvWrite|EvClosed|EvSignal) != 0 {
if err := bs.poller.del(ev); err != nil {
return err
}
Expand Down

0 comments on commit 03c93e1

Please sign in to comment.