Skip to content

Commit

Permalink
Merge pull request #11 from armanbilge/pr/exec-sched-tweaks
Browse files Browse the repository at this point in the history
Fixes for `EpollExecutorScheduler`
  • Loading branch information
armanbilge authored Aug 29, 2022
2 parents fc8e4b2 + 24b428c commit 116203e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/src/main/scala/epollcat/unsafe/EpollExecutorScheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import scala.scalanative.posix.unistd
import scala.scalanative.runtime._
import scala.scalanative.unsafe._
import scala.scalanative.unsigned._
import scala.util.control.NonFatal

import epoll._
import epollImplicits._
Expand All @@ -40,8 +41,10 @@ private[epollcat] final class EpollExecutorScheduler private (

def poll(timeout: Duration): Boolean = {
val timeoutIsInfinite = timeout == Duration.Inf
val noCallbacks = callbacks.isEmpty()

if (timeoutIsInfinite && callbacks.isEmpty()) false
if ((timeoutIsInfinite || timeout == Duration.Zero) && noCallbacks)
false // nothing to do here
else {
val timeoutMillis = if (timeoutIsInfinite) -1 else timeout.toMillis.toInt

Expand All @@ -54,11 +57,15 @@ private[epollcat] final class EpollExecutorScheduler private (
while (i < triggeredEvents) {
val event = events + i.toLong
val cb = fromPtr[Int => Unit](event.data)
cb(event.events.toInt)
try {
cb(event.events.toInt)
} catch {
case NonFatal(ex) => reportFailure(ex)
}
i += 1
}
} else {
reportFailure(new RuntimeException(s"epoll_wait: ${errno.errno}"))
throw new RuntimeException(s"epoll_wait: ${errno.errno}")
}

!callbacks.isEmpty()
Expand Down

0 comments on commit 116203e

Please sign in to comment.