Skip to content

Commit 2a7e076

Browse files
committed
Merge branch 'master' of github.com:swoole/swoole-src
2 parents 0abf591 + 75b7ffa commit 2a7e076

File tree

10 files changed

+93
-28
lines changed

10 files changed

+93
-28
lines changed

ext-src/php_swoole.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,13 @@ static void fatal_error(int code, const char *format, ...) {
418418
zend_end_try();
419419
}
420420

421+
static void bug_report_message_init() {
422+
SwooleG.bug_report_message += swoole::std_string::format(
423+
"PHP_VERSION : %s\n",
424+
PHP_VERSION
425+
);
426+
}
427+
421428
/* {{{ PHP_MINIT_FUNCTION
422429
*/
423430
PHP_MINIT_FUNCTION(swoole) {
@@ -745,6 +752,9 @@ PHP_MINIT_FUNCTION(swoole) {
745752
}
746753

747754
swoole_init();
755+
756+
// init bug report message
757+
bug_report_message_init();
748758
if (strcmp("cli", sapi_module.name) == 0 || strcmp("phpdbg", sapi_module.name) == 0) {
749759
SWOOLE_G(cli) = 1;
750760
}

ext-src/swoole_async_coro.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using swoole::Timer;
2929
using swoole::coroutine::Socket;
3030

3131
struct DNSCacheEntity {
32-
char address[16];
32+
char address[INET6_ADDRSTRLEN];
3333
time_t update_time;
3434
};
3535

ext-src/swoole_socket_coro.cc

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -843,9 +843,12 @@ static void sw_inline php_swoole_init_socket(zval *zobject, SocketObject *sock)
843843
sock->socket->set_zero_copy(true);
844844
sock->socket->set_buffer_allocator(sw_zend_string_allocator());
845845
zend_update_property_long(swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("fd"), sock->socket->get_fd());
846-
zend_update_property_long(swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("domain"), sock->socket->get_sock_domain());
847-
zend_update_property_long(swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("type"), sock->socket->get_sock_type());
848-
zend_update_property_long(swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("protocol"), sock->socket->get_sock_protocol());
846+
zend_update_property_long(
847+
swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("domain"), sock->socket->get_sock_domain());
848+
zend_update_property_long(
849+
swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("type"), sock->socket->get_sock_type());
850+
zend_update_property_long(
851+
swoole_socket_coro_ce, SW_Z8_OBJ_P(zobject), ZEND_STRL("protocol"), sock->socket->get_sock_protocol());
849852
}
850853

851854
SW_API bool php_swoole_export_socket(zval *zobject, Socket *_socket) {
@@ -1479,26 +1482,27 @@ static void swoole_socket_coro_read_vector(INTERNAL_FUNCTION_PARAMETERS, const b
14791482

14801483
std::unique_ptr<iovec[]> iov(new iovec[iovcnt]);
14811484

1482-
SW_HASHTABLE_FOREACH_START(vht, zelement)
1483-
if (!ZVAL_IS_LONG(zelement)) {
1484-
zend_throw_exception_ex(swoole_socket_coro_exception_ce,
1485-
EINVAL,
1486-
"Item #[%d] must be of type int, %s given",
1487-
iov_index,
1488-
zend_get_type_by_const(Z_TYPE_P(zelement)));
1489-
RETURN_FALSE;
1490-
}
1491-
if (Z_LVAL_P(zelement) < 0) {
1492-
zend_throw_exception_ex(
1493-
swoole_socket_coro_exception_ce, EINVAL, "Item #[%d] must be greater than 0", iov_index);
1494-
RETURN_FALSE;
1495-
}
1496-
size_t iov_len = Z_LVAL_P(zelement);
1485+
SW_HASHTABLE_FOREACH_START(vht, zelement) {
1486+
if (!ZVAL_IS_LONG(zelement)) {
1487+
zend_throw_exception_ex(swoole_socket_coro_exception_ce,
1488+
EINVAL,
1489+
"Item #[%d] must be of type int, %s given",
1490+
iov_index,
1491+
zend_get_type_by_const(Z_TYPE_P(zelement)));
1492+
RETURN_FALSE;
1493+
}
1494+
if (Z_LVAL_P(zelement) < 0) {
1495+
zend_throw_exception_ex(
1496+
swoole_socket_coro_exception_ce, EINVAL, "Item #[%d] must be greater than 0", iov_index);
1497+
RETURN_FALSE;
1498+
}
1499+
size_t iov_len = Z_LVAL_P(zelement);
14971500

1498-
iov[iov_index].iov_base = zend_string_alloc(iov_len, 0)->val;
1499-
iov[iov_index].iov_len = iov_len;
1500-
iov_index++;
1501-
total_length += iov_len;
1501+
iov[iov_index].iov_base = zend_string_alloc(iov_len, 0)->val;
1502+
iov[iov_index].iov_len = iov_len;
1503+
iov_index++;
1504+
total_length += iov_len;
1505+
}
15021506
SW_HASHTABLE_FOREACH_END();
15031507

15041508
swoole::network::IOVector io_vector((struct iovec *) iov.get(), iovcnt);
@@ -1533,6 +1537,7 @@ static void swoole_socket_coro_read_vector(INTERNAL_FUNCTION_PARAMETERS, const b
15331537
real_count = iov_index + 1;
15341538
zend_string *str = zend::fetch_zend_string_by_val((char *) iov[iov_index].iov_base);
15351539
iov[iov_index].iov_base = sw_zend_string_recycle(str, iov[iov_index].iov_len, offset_bytes)->val;
1540+
iov[iov_index].iov_len = offset_bytes;
15361541
free_func(iov.get(), iovcnt, real_count);
15371542
} else {
15381543
real_count = iovcnt;
@@ -1767,9 +1772,10 @@ static PHP_METHOD(swoole_socket_coro, getOption) {
17671772
}
17681773
case SO_RCVTIMEO:
17691774
case SO_SNDTIMEO: {
1770-
double timeout = sock->socket->get_timeout(optname == SO_RCVTIMEO ? Socket::TIMEOUT_READ : Socket::TIMEOUT_WRITE);
1775+
double timeout =
1776+
sock->socket->get_timeout(optname == SO_RCVTIMEO ? Socket::TIMEOUT_READ : Socket::TIMEOUT_WRITE);
17711777
array_init(return_value);
1772-
int sec = (int) timeout;
1778+
int sec = (int) timeout;
17731779
add_assoc_long(return_value, "sec", (int) timeout);
17741780
add_assoc_long(return_value, "usec", (timeout - (double) sec) * 1000000);
17751781
break;

include/swoole.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,9 @@ struct Global {
666666
//-----------------------[Hook]--------------------------
667667
void *hooks[SW_MAX_HOOK_TYPE];
668668
std::function<bool(Reactor *reactor, int &event_num)> user_exit_condition;
669+
670+
// bug report message
671+
std::string bug_report_message = "";
669672
};
670673

671674
std::string dirname(const std::string &file);

include/swoole_ssl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <openssl/x509.h>
3434
#include <openssl/x509v3.h>
3535
#include <openssl/rand.h>
36+
#include <openssl/opensslv.h>
3637

3738
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
3839
#define SW_SUPPORT_DTLS
@@ -169,5 +170,6 @@ void swoole_ssl_server_http_advise(swoole::SSLContext &);
169170
const char *swoole_ssl_get_error();
170171
int swoole_ssl_get_ex_connection_index();
171172
int swoole_ssl_get_ex_port_index();
173+
std::string swoole_ssl_get_version_message();
172174

173175
#endif

src/core/base.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "swoole_async.h"
4242
#include "swoole_c_api.h"
4343
#include "swoole_coroutine_c_api.h"
44+
#include "swoole_ssl.h"
4445

4546
using swoole::String;
4647

@@ -110,6 +111,30 @@ void *sw_realloc(void *ptr, size_t size) {
110111
return SwooleG.std_allocator.realloc(ptr, size);
111112
}
112113

114+
static void bug_report_message_init() {
115+
SwooleG.bug_report_message += "\n" + std::string(SWOOLE_BUG_REPORT) + "\n";
116+
117+
struct utsname u;
118+
if (uname(&u) != -1) {
119+
SwooleG.bug_report_message += swoole::std_string::format(
120+
"OS: %s %s %s %s\n",
121+
u.sysname,
122+
u.release,
123+
u.version,
124+
u.machine);
125+
}
126+
127+
#ifdef __VERSION__
128+
SwooleG.bug_report_message += swoole::std_string::format(
129+
"GCC_VERSION: %s\n",
130+
__VERSION__);
131+
#endif
132+
133+
#ifdef SW_USE_OPENSSL
134+
SwooleG.bug_report_message += swoole_ssl_get_version_message();
135+
136+
#endif
137+
}
113138
void swoole_init(void) {
114139
if (SwooleG.init) {
115140
return;
@@ -169,6 +194,9 @@ void swoole_init(void) {
169194
SwooleG.use_signalfd = 1;
170195
SwooleG.enable_signalfd = 1;
171196
#endif
197+
198+
// init bug report message
199+
bug_report_message_init();
172200
}
173201

174202
SW_EXTERN_C_BEGIN

src/network/dns.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ struct ResolvContext {
402402
int error;
403403
bool completed;
404404
Coroutine *co;
405+
std::shared_ptr<bool> defer_task_cancelled;
405406
std::unordered_map<int, network::Socket *> sockets;
406407
std::vector<std::string> result;
407408
};
@@ -428,6 +429,7 @@ std::vector<std::string> dns_lookup_impl_with_cares(const char *domain, int fami
428429
Coroutine *co = Coroutine::get_current_safe();
429430
ctx.co = co;
430431
ctx.completed = false;
432+
ctx.defer_task_cancelled = std::make_shared<bool>(false);
431433
char lookups[] = "fb";
432434
int res;
433435
ctx.ares_opts.lookups = lookups;
@@ -533,8 +535,12 @@ std::vector<std::string> dns_lookup_impl_with_cares(const char *domain, int fami
533535
}
534536
_resume:
535537
if (ctx->co && ctx->co->is_suspending()) {
538+
auto _cancelled = ctx->defer_task_cancelled;
536539
swoole_event_defer(
537-
[](void *data) {
540+
[_cancelled](void *data) {
541+
if (*_cancelled) {
542+
return;
543+
}
538544
Coroutine *co = reinterpret_cast<Coroutine *>(data);
539545
co->resume();
540546
},
@@ -573,6 +579,7 @@ std::vector<std::string> dns_lookup_impl_with_cares(const char *domain, int fami
573579
break;
574580
}
575581
}
582+
*ctx.defer_task_cancelled = true;
576583
ares_destroy(ctx.channel);
577584
_return:
578585
return ctx.result;

src/os/process_pool.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ int ProcessPool::wait() {
704704
exit_worker->id,
705705
exit_status.get_code(),
706706
exit_status.get_signal(),
707-
exit_status.get_signal() == SIGSEGV ? "\n" SWOOLE_BUG_REPORT : "");
707+
exit_status.get_signal() == SIGSEGV ? SwooleG.bug_report_message.c_str() : "");
708708
}
709709
new_pid = spawn(exit_worker);
710710
if (new_pid < 0) {

src/protocol/ssl.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swoole_string.h"
1919
#include "swoole_socket.h"
2020
#include "swoole_ssl.h"
21+
#include "swoole_util.h"
2122

2223
#ifdef SW_USE_OPENSSL
2324

@@ -54,6 +55,14 @@ static int swoole_ssl_verify_cookie(SSL *ssl, const uchar *cookie, uint cookie_l
5455
#define MAYBE_UNUSED
5556
#endif
5657

58+
std::string swoole_ssl_get_version_message() {
59+
std::string message = swoole::std_string::format(
60+
"OPENSSL_VERSION: %s\n",
61+
OPENSSL_VERSION_TEXT);
62+
63+
return message;
64+
}
65+
5766
static void MAYBE_UNUSED swoole_ssl_lock_callback(int mode, int type, const char *file, int line);
5867

5968
void swoole_ssl_init(void) {

src/server/manager.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void Server::check_worker_exit_status(int worker_id, const ExitStatus &exit_stat
209209
worker_id,
210210
exit_status.get_code(),
211211
exit_status.get_signal(),
212-
exit_status.get_signal() == SIGSEGV ? "\n" SWOOLE_BUG_REPORT : "");
212+
exit_status.get_signal() == SIGSEGV ? SwooleG.bug_report_message.c_str() : "");
213213
if (onWorkerError != nullptr) {
214214
onWorkerError(this, worker_id, exit_status);
215215
}

0 commit comments

Comments
 (0)