Skip to content

Commit 6936dcb

Browse files
committed
fix
1 parent 024200d commit 6936dcb

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

src/Events/SwooleEvent.php

+26-18
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ public function add($fd, $flag, $func, $args = [])
9595
return $timerId;
9696
case EventInterface::EV_READ:
9797
if (\is_resource($fd)) {
98-
if ($this->_reads[$key = (int) $fd] ?? null) {
98+
if (
99+
($this->_reads[$key = (int) $fd] ?? null) or
100+
Event::isset($fd, SWOOLE_EVENT_READ)
101+
) {
99102
$this->del($fd, EventInterface::EV_READ);
100103
}
101104
if ($res = Event::add($fd, $func, null, SWOOLE_EVENT_READ)) {
@@ -108,7 +111,10 @@ public function add($fd, $flag, $func, $args = [])
108111
return false;
109112
case self::EV_WRITE:
110113
if (\is_resource($fd)) {
111-
if ($this->_writes[$key = (int) $fd] ?? null) {
114+
if (
115+
($this->_writes[$key = (int) $fd] ?? null) or
116+
Event::isset($fd, SWOOLE_EVENT_WRITE)
117+
) {
112118
$this->del($fd, EventInterface::EV_WRITE);
113119
}
114120
if ($res = Event::add($fd, null, $func, SWOOLE_EVENT_WRITE)) {
@@ -150,30 +156,32 @@ public function del($fd, $flag)
150156

151157
return false;
152158
case self::EV_READ:
153-
if (
154-
\is_resource($fd) and
155-
isset($this->_reads[$key = (int) $fd]) and
156-
Event::isset($fd, SWOOLE_EVENT_READ)
157-
) {
158-
if (Event::del($fd)) {
159-
unset($this->_reads[$key]);
159+
if (\is_resource($fd)) {
160+
$key = (int) $fd;
161+
if (Event::isset($fd, SWOOLE_EVENT_READ)){
162+
if (Event::del($fd)) {
160163

161-
return true;
164+
return false;
165+
}
162166
}
167+
unset($this->_reads[$key]);
168+
169+
return true;
163170
}
164171

165172
return false;
166173
case self::EV_WRITE:
167-
if (
168-
\is_resource($fd) and
169-
isset($this->_writes[$key = (int) $fd]) and
170-
Event::isset($fd, SWOOLE_EVENT_WRITE)
171-
) {
172-
if (Event::del($fd)) {
173-
unset($this->_writes[$key]);
174+
if (\is_resource($fd)) {
175+
$key = (int) $fd;
176+
if (Event::isset($fd, SWOOLE_EVENT_WRITE)){
177+
if (Event::del($fd)) {
174178

175-
return true;
179+
return false;
180+
}
176181
}
182+
unset($this->_writes[$key]);
183+
184+
return true;
177185
}
178186

179187
return false;

tests/EventsCase/SwooleEventTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public function testAddAndDelRead()
135135
$this->assertNull($writeCallback);
136136
return true;
137137
});
138+
$eventMock->shouldReceive('isset')->andReturn(false);
138139

139140
$stream = fopen('php://memory', 'r+');
140141
$result = $swooleEvent->add($stream, EventInterface::EV_READ, function () {
@@ -163,6 +164,7 @@ public function testAddAndDelWrite()
163164
$this->assertNull($readCallback);
164165
return true;
165166
});
167+
$eventMock->shouldReceive('isset')->andReturn(false);
166168

167169
$stream = fopen('php://memory', 'w+');
168170
$result = $swooleEvent->add($stream, EventInterface::EV_WRITE, function () {

0 commit comments

Comments
 (0)