Skip to content

Commit

Permalink
Merge branch 'master' into support-pty
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Apr 9, 2024
2 parents 6122ab9 + b36b304 commit 76e4bef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
57 changes: 43 additions & 14 deletions ext-src/php_swoole_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
+----------------------------------------------------------------------+
*/

/* $Id: d0ac03753a22ce34a521c7eb75b2e19f0d6ec961 */
/* $Id: 3bc066dd5d5f3498f7bb2ef8c5a7408d0cd33149 */

#ifndef SWOOLE_LIBRARY_H
#define SWOOLE_LIBRARY_H

#include "zend_exceptions.h"

#if PHP_VERSION_ID < 80000
typedef zval zend_source_string_t;
#else
Expand Down Expand Up @@ -1939,8 +1941,14 @@ static const char* swoole_library_source_core_coroutine_http_client_proxy =
"\n"
"class ClientProxy\n"
"{\n"
" public function __construct(private string $body, private int $statusCode, private array $headers, private array $cookies)\n"
" private array $headers;\n"
"\n"
" private array $cookies;\n"
"\n"
" public function __construct(private string $body, private int $statusCode, ?array $headers, ?array $cookies)\n"
" {\n"
" $this->headers = $headers ?? [];\n"
" $this->cookies = $cookies ?? [];\n"
" }\n"
"\n"
" public function getBody(): string\n"
Expand Down Expand Up @@ -2036,8 +2044,8 @@ static const char* swoole_library_source_core_coroutine_http_functions =
" return new ClientProxy(\n"
" $client->getBody(),\n"
" $client->getStatusCode(),\n"
" $client->getHeaders(),\n"
" $client->getCookies()\n"
" $client->getHeaders() ?: [],\n"
" $client->getCookies() ?: []\n"
" );\n"
" }\n"
" throw new Exception($client->errMsg, $client->errCode);\n"
Expand Down Expand Up @@ -2107,7 +2115,7 @@ static const char* swoole_library_source_core_coroutine_http_functions =
" }\n"
" $body = curl_exec($ch);\n"
" if ($body !== false) {\n"
" return new ClientProxy($body, curl_getinfo($ch, CURLINFO_HTTP_CODE), $responseHeaders, $responseCookies);\n"
" return new ClientProxy($body, curl_getinfo($ch, CURLINFO_RESPONSE_CODE), $responseHeaders, $responseCookies);\n"
" }\n"
" throw new Exception(curl_error($ch), curl_errno($ch));\n"
"}\n"
Expand Down Expand Up @@ -2219,6 +2227,12 @@ static const char* swoole_library_source_core_connection_pool =
" }\n"
" }\n"
"\n"
" /**\n"
" * Get a connection from the pool.\n"
" *\n"
" * @param float $timeout > 0 means waiting for the specified number of seconds. other means no waiting.\n"
" * @return mixed|false Returns a connection object from the pool, or false if the pool is full and the timeout is reached.\n"
" */\n"
" public function get(float $timeout = -1)\n"
" {\n"
" if ($this->pool === null) {\n"
Expand Down Expand Up @@ -2749,26 +2763,28 @@ static const char* swoole_library_source_core_database_detects_lost_connections
" 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',\n"
" 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for',\n"
" 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',\n"
" 'SQLSTATE[HY000] [2002] Connection timed out',\n"
" 'SSL: Connection timed out',\n"
" 'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',\n"
" 'Temporary failure in name resolution',\n"
" 'SSL: Broken pipe',\n"
" 'SQLSTATE[08S01]: Communication link failure',\n"
" 'SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host',\n"
" 'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: No route to host',\n"
" 'The client was disconnected by the server because of inactivity. See wait_timeout and interactive_timeout for configuring this behavior.',\n"
" 'SQLSTATE[08006] [7] could not translate host name',\n"
" 'TCP Provider: Error code 0x274C',\n"
" 'SQLSTATE[HY000] [2002] No such file or directory',\n"
" 'SSL: Operation timed out',\n"
" 'Reason: Server is in script upgrade mode. Only administrator can connect at this time.',\n"
" 'Unknown $curl_error_code: 77',\n"
" 'SSL: Handshake timed out',\n"
" 'SQLSTATE[08006] [7] SSL error: sslv3 alert unexpected message',\n"
" 'SQLSTATE[08006] [7] unrecognized SSL error code:',\n"
" 'SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it',\n"
" 'Broken pipe',\n"
" // PDO::prepare(): Send of 77 bytes failed with errno=110 Operation timed out\n"
" // SSL: Handshake timed out\n"
" // SSL: Operation timed out\n"
" // SSL: Connection timed out\n"
" // SQLSTATE[HY000] [2002] Connection timed out\n"
" 'timed out',\n"
" 'Error reading result',\n"
" ];\n"
"\n"
" public static function causedByLostConnection(\\Throwable $e): bool\n"
Expand Down Expand Up @@ -2971,11 +2987,23 @@ static const char* swoole_library_source_core_database_pdo_pool =
" }, $size, PDOProxy::class);\n"
" }\n"
"\n"
" /**\n"
" * Get a PDO connection from the pool. The PDO connection (a PDO object) is wrapped in a PDOProxy object returned.\n"
" *\n"
" * @param float $timeout > 0 means waiting for the specified number of seconds. other means no waiting.\n"
" * @return PDOProxy|false Returns a PDOProxy object from the pool, or false if the pool is full and the timeout is reached.\n"
" * {@inheritDoc}\n"
" */\n"
" public function get(float $timeout = -1)\n"
" {\n"
" /* @var \\Swoole\\Database\\PDOProxy|false $pdo */\n"
" $pdo = parent::get($timeout);\n"
" /* @var \\Swoole\\Database\\PDOProxy $pdo */\n"
" if ($pdo === false) {\n"
" return false;\n"
" }\n"
"\n"
" $pdo->reset();\n"
"\n"
" return $pdo;\n"
" }\n"
"\n"
Expand Down Expand Up @@ -6610,6 +6638,7 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client =
"\n"
"namespace Swoole\\Coroutine\\FastCGI;\n"
"\n"
"use Swoole\\Constant;\n"
"use Swoole\\Coroutine\\FastCGI\\Client\\Exception;\n"
"use Swoole\\Coroutine\\Socket;\n"
"use Swoole\\FastCGI\\FrameParser;\n"
Expand Down Expand Up @@ -6656,8 +6685,8 @@ static const char* swoole_library_source_core_coroutine_fast_cgi_client =
" if (!isset($this->socket)) {\n"
" $this->socket = $socket = new Socket($this->af, SOCK_STREAM, IPPROTO_IP);\n"
" $socket->setProtocol([\n"
" 'open_ssl' => $this->ssl,\n"
" 'open_fastcgi_protocol' => true,\n"
" Constant::OPTION_OPEN_SSL => $this->ssl,\n"
" Constant::OPTION_OPEN_FASTCGI_PROTOCOL => true,\n"
" ]);\n"
" if (!$socket->connect($this->host, $this->port, $timeout)) {\n"
" $this->ioException();\n"
Expand Down Expand Up @@ -9822,7 +9851,7 @@ static const char* swoole_library_source_alias_ns =
" }\n"
"}\n";

void php_swoole_load_library()
void php_swoole_load_library(void)
{
_eval(swoole_library_source_constants, "@swoole/library/constants.php");
_eval(swoole_library_source_std_exec, "@swoole/library/std/exec.php");
Expand Down
3 changes: 1 addition & 2 deletions src/network/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,7 @@ ssize_t Socket::ssl_recv(void *__buf, size_t __n) {
return SW_ERR;

case SSL_ERROR_SYSCALL:
errno = SW_ERROR_SSL_RESET;
return SW_ERR;
return errno == 0 ? 0 : SW_ERR;

case SSL_ERROR_SSL:
ssl_catch_error();
Expand Down
2 changes: 1 addition & 1 deletion src/server/master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ Connection *Server::add_connection(ListenPort *ls, Socket *_socket, int server_f

// TCP Nodelay
if (ls->open_tcp_nodelay && (ls->type == SW_SOCK_TCP || ls->type == SW_SOCK_TCP6)) {
if (ls->socket->set_tcp_nodelay() != 0) {
if (_socket->set_tcp_nodelay() != 0) {
swoole_sys_warning("setsockopt(TCP_NODELAY) failed");
}
_socket->enable_tcp_nodelay = true;
Expand Down
2 changes: 1 addition & 1 deletion tests/swoole_http_server_coro/close_socket.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $pm->parentFunc = function () use ($pm) {
for ($i = 0; $i < 2; $i++) {
$cli = new Client('127.0.0.1', $pm->getFreePort());
Assert::assert($cli->get('/'));
Assert::contains($cli->headers['server'], 'BWS');
Assert::assert(str_contains($cli->headers['server'], 'BWS') or str_contains($cli->headers['server'], 'bfe'));
}
});
echo "DONE\n";
Expand Down

0 comments on commit 76e4bef

Please sign in to comment.