walkor 2 years ago
parent
commit
c5fdf9a243

+ 3 - 3
src/Connection/AsyncUdpConnection.php

@@ -99,7 +99,7 @@ class AsyncUdpConnection extends UdpConnection
      */
      */
     public function baseRead($socket)
     public function baseRead($socket)
     {
     {
-        $recvBuffer = stream_socket_recvfrom($socket, Worker::MAX_UDP_PACKAGE_SIZE, 0, $remoteAddress);
+        $recvBuffer = stream_socket_recvfrom($socket, static::MAX_UDP_PACKAGE_SIZE, 0, $remoteAddress);
         if (false === $recvBuffer || empty($remoteAddress)) {
         if (false === $recvBuffer || empty($remoteAddress)) {
             return;
             return;
         }
         }
@@ -194,13 +194,13 @@ class AsyncUdpConnection extends UdpConnection
 
 
         if (!$this->socket) {
         if (!$this->socket) {
             Worker::safeEcho(new Exception($errmsg));
             Worker::safeEcho(new Exception($errmsg));
+            $this->eventLoop = null;
             return;
             return;
         }
         }
 
 
         stream_set_blocking($this->socket, false);
         stream_set_blocking($this->socket, false);
-
         if ($this->onMessage) {
         if ($this->onMessage) {
-            $this->eventLoop->onWritable($this->socket, [$this, 'baseRead']);
+            $this->eventLoop->onReadable($this->socket, [$this, 'baseRead']);
         }
         }
         $this->connected = true;
         $this->connected = true;
         // Try to emit onConnect callback.
         // Try to emit onConnect callback.

+ 7 - 0
src/Connection/UdpConnection.php

@@ -32,6 +32,13 @@ use function trim;
 class UdpConnection extends ConnectionInterface implements JsonSerializable
 class UdpConnection extends ConnectionInterface implements JsonSerializable
 {
 {
     /**
     /**
+     * Max udp package size.
+     *
+     * @var int
+     */
+    const MAX_UDP_PACKAGE_SIZE = 65535;
+
+    /**
      * Transport layer protocol.
      * Transport layer protocol.
      *
      *
      * @var string
      * @var string

+ 3 - 0
src/Protocols/Http/Request.php

@@ -653,6 +653,9 @@ class Request
      */
      */
     protected function setSidCookie(string $sessionName, string $sid, array $cookieParams)
     protected function setSidCookie(string $sessionName, string $sid, array $cookieParams)
     {
     {
+        if (!$this->connection) {
+            throw new RuntimeException('Request->setSidCookie() fail, header already send');
+        }
         $this->connection->headers['Set-Cookie'] = [$sessionName . '=' . $sid
         $this->connection->headers['Set-Cookie'] = [$sessionName . '=' . $sid
             . (empty($cookieParams['domain']) ? '' : '; Domain=' . $cookieParams['domain'])
             . (empty($cookieParams['domain']) ? '' : '; Domain=' . $cookieParams['domain'])
             . (empty($cookieParams['lifetime']) ? '' : '; Max-Age=' . $cookieParams['lifetime'])
             . (empty($cookieParams['lifetime']) ? '' : '; Max-Age=' . $cookieParams['lifetime'])

+ 1 - 7
src/Worker.php

@@ -74,12 +74,6 @@ class Worker
      * @var int
      * @var int
      */
      */
     const DEFAULT_BACKLOG = 102400;
     const DEFAULT_BACKLOG = 102400;
-    /**
-     * Max udp package size.
-     *
-     * @var int
-     */
-    const MAX_UDP_PACKAGE_SIZE = 65535;
 
 
     /**
     /**
      * The safe distance for columns adjacent
      * The safe distance for columns adjacent
@@ -2495,7 +2489,7 @@ class Worker
     {
     {
         \set_error_handler(function () {
         \set_error_handler(function () {
         });
         });
-        $recvBuffer = \stream_socket_recvfrom($socket, static::MAX_UDP_PACKAGE_SIZE, 0, $remoteAddress);
+        $recvBuffer = \stream_socket_recvfrom($socket, UdpConnection::MAX_UDP_PACKAGE_SIZE, 0, $remoteAddress);
         \restore_error_handler();
         \restore_error_handler();
         if (false === $recvBuffer || empty($remoteAddress)) {
         if (false === $recvBuffer || empty($remoteAddress)) {
             return false;
             return false;