diff --git a/aio_linux.go b/aio_linux.go index 962c8db..dd74be5 100644 --- a/aio_linux.go +++ b/aio_linux.go @@ -68,9 +68,10 @@ func (p *poller) Watch(fd int) error { func (p *poller) Wait(chEventNotify chan pollerEvents, die chan struct{}) { events := make([]syscall.EpollEvent, maxEvents) - swapEvents := make(chan pollerEvents, 2) - for i := 0; i < cap(swapEvents); i++ { - swapEvents <- make([]event, 0, maxEvents) + swapEvents := make([]pollerEvents, 2) + swapIdx := 0 + for i := 0; i < len(swapEvents); i++ { + swapEvents[i] = make([]event, 0, maxEvents) } for { @@ -88,8 +89,9 @@ func (p *poller) Wait(chEventNotify chan pollerEvents, die chan struct{}) { } // note chan swap must not continue unexpected - pe := <-swapEvents + pe := swapEvents[swapIdx] pe = pe[:0] + swapIdx = (swapIdx + 1) % len(swapEvents) for i := 0; i < n; i++ { ev := &events[i] @@ -115,7 +117,6 @@ func (p *poller) Wait(chEventNotify chan pollerEvents, die chan struct{}) { select { case chEventNotify <- pe: - swapEvents <- pe case <-die: return }