Skip to content

Commit

Permalink
swow
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Feb 2, 2025
1 parent 4deadc9 commit 754861f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Events/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ protected function setNextTickTime(float $nextTickTime): void
{
$this->nextTickTime = $nextTickTime;
if ($nextTickTime == 0) {
// Set a shorter timeout so that swow can timely detect the signal.
$this->selectTimeout = 800000;
return;
}
Expand Down
11 changes: 7 additions & 4 deletions src/Events/Swow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Workerman\Events;

use RuntimeException;
use Workerman\Coroutine\Coroutine\Swow as Coroutine;
use Swow\Signal;
use Swow\SignalException;
Expand Down Expand Up @@ -141,19 +142,21 @@ public function onReadable($stream, callable $func): void
$this->offReadable($stream);
break;
}
$rEvent = stream_poll_one($stream, STREAM_POLLIN | STREAM_POLLHUP);
// Under Windows, setting a timeout is necessary; otherwise, the accept cannot be listened to.
// Setting it to 1000ms will result in a 1-second delay for the first accept under Windows.
$rEvent = stream_poll_one($stream, STREAM_POLLIN | STREAM_POLLHUP, 1000);
if (!isset($this->readEvents[$fd]) || $this->readEvents[$fd] !== Coroutine::getCurrent()) {
break;
}
if ($rEvent !== STREAM_POLLNONE) {
$this->safeCall($func, [$stream]);
}
if ($rEvent !== STREAM_POLLIN) {
if ($rEvent !== STREAM_POLLIN && $rEvent !== STREAM_POLLNONE) {
$this->offReadable($stream);
break;
}
}
} catch (\RuntimeException) {
} catch (RuntimeException) {
$this->offReadable($stream);
}
});
Expand Down Expand Up @@ -198,7 +201,7 @@ public function onWritable($stream, callable $func): void
break;
}
}
} catch (\RuntimeException) {
} catch (RuntimeException) {
$this->offWritable($stream);
}
});
Expand Down

0 comments on commit 754861f

Please sign in to comment.