|
@@ -25,7 +25,6 @@ class buffer_looper
|
|
|
protected $mBuffers;
|
|
|
protected $mContents;
|
|
|
protected $mProcessor;
|
|
|
- protected $mBufferID;
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
@@ -37,7 +36,6 @@ class buffer_looper
|
|
|
$this->mEvConnects = [];
|
|
|
$this->mEvTimeouts = [];
|
|
|
|
|
|
- $this->mBufferID = 1;
|
|
|
//event_init(); //for libevent C 库 2.16 版本
|
|
|
$this->mEvBase = event_base_new();
|
|
|
}
|
|
@@ -131,13 +129,10 @@ class buffer_looper
|
|
|
$this->mBuffers = [];
|
|
|
|
|
|
foreach ($this->mStreams as $fd => $stream) {
|
|
|
- @socket_shutdown($this->mStreams[$fd],STREAM_SHUT_RDWR);
|
|
|
- @socket_close($this->mStreams[$fd]);
|
|
|
+ socket_close($this->mStreams[$fd]);
|
|
|
}
|
|
|
- $this->mStreams = [];
|
|
|
-
|
|
|
+ $this->mStreams = [];
|
|
|
$this->mContents = [];
|
|
|
-
|
|
|
foreach ($this->mEvSignals as $event) {
|
|
|
event_del($event);
|
|
|
event_free($event);
|
|
@@ -165,8 +160,7 @@ class buffer_looper
|
|
|
|
|
|
private function add_stream($stream)
|
|
|
{
|
|
|
- $bufid = $this->mBufferID;
|
|
|
-
|
|
|
+ $bufid = intval($stream);
|
|
|
socket_set_nonblock($stream);
|
|
|
$buffer = event_buffer_new($stream, [$this,'onRead'], NULL, [$this,'onError'], $bufid);
|
|
|
|
|
@@ -186,9 +180,6 @@ class buffer_looper
|
|
|
$this->mBuffers[$bufid] = $buffer;
|
|
|
$this->mContents[$bufid] = "";
|
|
|
|
|
|
- $this->mBufferID++;
|
|
|
- if($this->mBufferID < 0) $this->mBufferID = 1;
|
|
|
-
|
|
|
return $bufid;
|
|
|
}
|
|
|
}
|
|
@@ -358,7 +349,6 @@ class buffer_looper
|
|
|
event_buffer_free($buffer);
|
|
|
|
|
|
if(array_key_exists($bufid,$this->mStreams)) {
|
|
|
- @socket_shutdown($this->mStreams[$bufid],STREAM_SHUT_RDWR);
|
|
|
socket_close($this->mStreams[$bufid]);
|
|
|
unset($this->mStreams[$bufid]);
|
|
|
}
|
|
@@ -448,13 +438,11 @@ class buffer_looper
|
|
|
if(!array_key_exists($bufid,$this->mBuffers)) return false;
|
|
|
|
|
|
Log::record(__METHOD__ . " close socket.",Log::DEBUG);
|
|
|
-
|
|
|
$buffer = $this->mBuffers[$bufid];
|
|
|
event_buffer_disable($buffer, EV_READ | EV_WRITE);
|
|
|
event_buffer_free($buffer);
|
|
|
|
|
|
if(array_key_exists($bufid,$this->mStreams)) {
|
|
|
- @socket_shutdown($this->mStreams[$bufid],STREAM_SHUT_RDWR);
|
|
|
socket_close($this->mStreams[$bufid]);
|
|
|
unset($this->mStreams[$bufid]);
|
|
|
}
|