Parcourir la source

解决发送消息插队问题

liangl il y a 11 ans
Parent
commit
2ce227bbf6
1 fichiers modifiés avec 6 ajouts et 0 suppressions
  1. 6 0
      workerman/Core/SocketWorker.php

+ 6 - 0
workerman/Core/SocketWorker.php

@@ -527,6 +527,11 @@ abstract class SocketWorker extends AbstractWorker
         // tcp
         if($this->protocol != 'udp')
         {
+            if(!empty($this->sendBuffers[$this->currentDealFd]))
+            {
+                $this->sendBuffers[$this->currentDealFd] .= $str_to_send;
+                return;
+            }
             $send_len = @fwrite($this->connections[$this->currentDealFd], $str_to_send);
             if($send_len === strlen($str_to_send))
             {
@@ -578,6 +583,7 @@ abstract class SocketWorker extends AbstractWorker
             {
                 return $this->closeClient($fd);
             }
+            $this->sendBuffers[$fd] = '';
             $this->event->del($this->connections[$fd], BaseEvent::EV_WRITE);
             return;
         }