Pārlūkot izejas kodu

fix socket shut down err

stanley-king 6 gadi atpakaļ
vecāks
revīzija
c4c99bdd74
2 mainītis faili ar 5 papildinājumiem un 17 dzēšanām
  1. 3 15
      helper/event/buffer_looper.php
  2. 2 2
      helper/search/tcp_client.php

+ 3 - 15
helper/event/buffer_looper.php

@@ -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]);
         }

+ 2 - 2
helper/search/tcp_client.php

@@ -87,10 +87,10 @@ abstract class tcp_client
         $host = $this->remote_addr();
         $this->mSocket = @stream_socket_client ($host,$err,$errno,30);
         if($this->mSocket == false) {
-            Log::record("connect server err host:{$host} code:{$errno} : {$err}");
+            Log::record("connect server err host:{$host} code:{$errno} : {$err}",Log::ERR);
             return false;
         } else {
-            Log::record("connect server succ host:{$host} code:{$errno} : {$err}");
+            Log::record("connect server succ host:{$host} code:{$errno} : {$err}",LOG::DEBUG);
             socket_set_timeout($this->mSocket,self::time_out);
             return true;
         }