Skip to content

Commit a996695

Browse files
committed
[EventLoop] Fix issues when removing streams with libevent.
When doing two consecutive updates on an event resource inside the same tick, pecl-libevent seems to get stuck without properly freeing up the event. It is still unclear if it is something related to pecl-libevent or libevent itself, but our new approach seems to fix this problem. For now we just delete the previous resource and create a new one one on the associated stream using the new flags. This commit should fix issue #9.
1 parent 9044dc0 commit a996695

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

LibEventLoop.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,16 @@ protected function removeStreamEvent($stream, $eventClass, $eventCallbacks)
112112
$event = $this->events[$id];
113113

114114
event_del($event);
115+
event_free($event);
116+
unset($this->{"{$eventCallbacks}Callbacks"}[$id]);
117+
118+
$event = event_new();
115119
event_set($event, $stream, $flags | EV_PERSIST, $this->callback, $this);
120+
event_base_set($event, $this->base);
116121
event_add($event);
117122

123+
$this->events[$id] = $event;
118124
$this->flags[$id] = $flags;
119-
unset($this->{"{$eventCallbacks}Callbacks"}[$id]);
120125
}
121126
}
122127

@@ -127,15 +132,15 @@ public function removeStream($stream)
127132
if (isset($this->events[$id])) {
128133
$event = $this->events[$id];
129134

130-
event_del($event);
131-
event_free($event);
132-
133135
unset(
134136
$this->events[$id],
135137
$this->flags[$id],
136138
$this->readCallbacks[$id],
137139
$this->writeCallbacks[$id]
138140
);
141+
142+
event_del($event);
143+
event_free($event);
139144
}
140145
}
141146

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy