Skip to content

Commit bbc4cc3

Browse files
authored
Merge pull request #1113 from lvluoyue/patch-1
修复swow协程的错误
2 parents 8dadbe7 + 55fb36a commit bbc4cc3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Connection/TcpConnection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ public function baseRead($socket, bool $checkEof = true): void
661661

662662
// Check connection closed.
663663
if ($buffer === '' || $buffer === false) {
664-
if ($checkEof && (feof($socket) || !is_resource($socket) || $buffer === false)) {
664+
if ($checkEof && (!is_resource($socket) || feof($socket) || $buffer === false)) {
665665
$this->destroy();
666666
return;
667667
}
@@ -835,7 +835,7 @@ public function baseWrite(): void
835835
*/
836836
public function doSslHandshake($socket): bool|int
837837
{
838-
if (feof($socket)) {
838+
if (!is_resource($socket) || feof($socket)) {
839839
$this->destroy();
840840
return false;
841841
}

src/Events/Swow.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,18 @@ public function onWritable($stream, callable $func): void
189189
try {
190190
$this->writeEvents[$fd] = Coroutine::getCurrent();
191191
while (true) {
192-
$rEvent = stream_poll_one($stream, STREAM_POLLOUT | STREAM_POLLHUP);
192+
if (!is_resource($stream)) {
193+
$this->offWritable($stream);
194+
break;
195+
}
193196
if (!isset($this->writeEvents[$fd]) || $this->writeEvents[$fd] !== Coroutine::getCurrent()) {
194197
break;
195198
}
199+
$rEvent = stream_poll_one($stream, STREAM_POLLOUT | STREAM_POLLHUP, 1000);
196200
if ($rEvent !== STREAM_POLLNONE) {
197201
$this->safeCall($func, [$stream]);
198202
}
199-
if ($rEvent !== STREAM_POLLOUT) {
203+
if ($rEvent !== STREAM_POLLOUT && $rEvent !== STREAM_POLLNONE) {
200204
$this->offWritable($stream);
201205
break;
202206
}

0 commit comments

Comments
 (0)