Skip to content

Commit

Permalink
signal event
Browse files Browse the repository at this point in the history
  • Loading branch information
cheng-zhongliang committed Jul 26, 2023
1 parent 2d158f3 commit c4ad54d
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions epoll.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package event

import (
"encoding/binary"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -218,10 +217,7 @@ func (ep *Epoll) InitSignalPoll() error {
for {
select {
case sig := <-ch:
sigNum := sig.(syscall.Signal)
buf := make([]byte, binary.MaxVarintLen64)
n := binary.PutUvarint(buf, uint64(sigNum))
syscall.Write(ep.SignalFd1, buf[:n])
syscall.Write(ep.SignalFd1, []byte{byte(sig.(syscall.Signal))})
case <-ep.ExitCh:
return
}
Expand All @@ -233,11 +229,10 @@ func (ep *Epoll) InitSignalPoll() error {

// OnSignal is the callback function when a signal is received.
func (ep *Epoll) OnSignal(cb func(ev *Event, res uint32), fd int) {
buf := make([]byte, binary.MaxVarintLen64)
buf := make([]byte, 1)
syscall.Read(fd, buf)

sigNum, _ := binary.Uvarint(buf)
ev, ok := ep.SignalEvs[int(sigNum)]
ev, ok := ep.SignalEvs[int(buf[0])]
if !ok {
return
}
Expand Down

0 comments on commit c4ad54d

Please sign in to comment.