Browse Source

read nothing then close connection

walkor 9 years ago
parent
commit
d27d23632e
4 changed files with 20 additions and 21 deletions
  1. 3 3
      Connection/TcpConnection.php
  2. 14 15
      Events/Select.php
  3. 2 2
      Protocols/Http.php
  4. 1 1
      Worker.php

+ 3 - 3
Connection/TcpConnection.php

@@ -334,7 +334,7 @@ class TcpConnection extends ConnectionInterface
         {
             Worker::$globalEvent->add($this->_socket, EventInterface::EV_READ, array($this, 'baseRead'));
             $this->_isPaused = false;
-            $this->baseRead($this->_socket);
+            $this->baseRead($this->_socket, false);
         }
     }
 
@@ -343,7 +343,7 @@ class TcpConnection extends ConnectionInterface
      * @param resource $socket
      * @return void
      */
-    public function baseRead($socket)
+    public function baseRead($socket, $check_eof = true)
     {
         $read_data = false;
         while(1)
@@ -358,7 +358,7 @@ class TcpConnection extends ConnectionInterface
         }
         
         // Check connection closed.
-        if(!$read_data && (!is_resource($socket) || feof($socket)))
+        if(!$read_data && $check_eof)
         {
             $this->destroy();
             return;

+ 14 - 15
Events/Select.php

@@ -231,34 +231,33 @@ class Select implements EventInterface
             $read = $this->_readFds;
             $write = $this->_writeFds;
             // Waiting read/write/signal/timeout events.
-            @stream_select($read, $write, $e, 0, $this->_selectTimeout);
+            $ret = @stream_select($read, $write, $e, 0, $this->_selectTimeout);
             
             if(!$this->_scheduler->isEmpty())
             {
                 $this->tick();
             }
             
-            if($read)
+            if(!$ret)
             {
-                foreach($read as $fd)
+                continue;
+            }
+            
+            foreach($read as $fd)
+            {
+                $fd_key = (int) $fd;
+                if(isset($this->_allEvents[$fd_key][self::EV_READ]))
                 {
-                    $fd_key = (int) $fd;
-                    if(isset($this->_allEvents[$fd_key][self::EV_READ]))
-                    {
-                        call_user_func_array($this->_allEvents[$fd_key][self::EV_READ][0], array($this->_allEvents[$fd_key][self::EV_READ][1]));
-                    }
+                    call_user_func_array($this->_allEvents[$fd_key][self::EV_READ][0], array($this->_allEvents[$fd_key][self::EV_READ][1]));
                 }
             }
             
-            if($write)
+            foreach($write as $fd)
             {
-                foreach($write as $fd)
+                $fd_key = (int) $fd;
+                if(isset($this->_allEvents[$fd_key][self::EV_WRITE]))
                 {
-                    $fd_key = (int) $fd;
-                    if(isset($this->_allEvents[$fd_key][self::EV_WRITE]))
-                    {
-                        call_user_func_array($this->_allEvents[$fd_key][self::EV_WRITE][0], array($this->_allEvents[$fd_key][self::EV_WRITE][1]));
-                    }
+                    call_user_func_array($this->_allEvents[$fd_key][self::EV_WRITE][0], array($this->_allEvents[$fd_key][self::EV_WRITE][1]));
                 }
             }
         }

+ 2 - 2
Protocols/Http.php

@@ -46,8 +46,8 @@ class Http
             $match = array();
             if(preg_match("/\r\nContent-Length: ?(\d+)/", $header, $match))
             {
-                $content_lenght = $match[1];
-                return $content_lenght + strlen($header) + 4;
+                $content_length = $match[1];
+                return $content_length + strlen($header) + 4;
             }
             else
             {

+ 1 - 1
Worker.php

@@ -32,7 +32,7 @@ class Worker
      * Version.
      * @var string
      */
-    const VERSION = '3.2.8';
+    const VERSION = '3.2.9';
     
     /**
      * Status starting.