From 7be195caa7589560d5e1a019e389850fdb5c8a1e Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sat, 9 Apr 2022 15:08:41 +0100 Subject: [PATCH] Support fpm_get_socket_listening_queue on macOS Using TCP_CONNECTION_INFO socket option. --- NEWS | 1 + sapi/fpm/config.m4 | 13 +++++++++++++ sapi/fpm/fpm/fpm_config.h | 2 +- sapi/fpm/fpm/fpm_sockets.c | 24 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f6c2e34f3cd..b1d63069e28 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS . Emit error for invalid port setting. (David Carlier) . Added extra check for FPM proc dumpable on SELinux based systems. (David Carlier) + . Added support for listening queue on macOS. (David Carlier) - Intl: . Update all grandfathered language tags with preferred values diff --git a/sapi/fpm/config.m4 b/sapi/fpm/config.m4 index 4e3815ffc25..0fede79c23f 100644 --- a/sapi/fpm/config.m4 +++ b/sapi/fpm/config.m4 @@ -343,6 +343,19 @@ AC_DEFUN([AC_FPM_LQ], AC_DEFINE([HAVE_LQ_TCP_INFO], 1, [do we have TCP_INFO?]) fi + AC_MSG_CHECKING([for TCP_CONNECTION_INFO]) + + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[struct tcp_connection_info ti; int x = TCP_CONNECTION_INFO;]])], [ + have_lq=tcp_connection_info + AC_MSG_RESULT([yes]) + ], [ + AC_MSG_RESULT([no]) + ]) + + if test "$have_lq" = "tcp_connection_info"; then + AC_DEFINE([HAVE_LQ_TCP_CONNECTION_INFO], 1, [do we have TCP_CONNECTION_INFO?]) + fi + if test "$have_lq" = "no" ; then AC_MSG_CHECKING([for SO_LISTENQLEN]) diff --git a/sapi/fpm/fpm/fpm_config.h b/sapi/fpm/fpm/fpm_config.h index 548202fe3a5..d34f686a6fb 100644 --- a/sapi/fpm/fpm/fpm_config.h +++ b/sapi/fpm/fpm/fpm_config.h @@ -70,7 +70,7 @@ # define HAVE_FPM_TRACE 0 #endif -#if defined(HAVE_LQ_TCP_INFO) || defined(HAVE_LQ_SO_LISTENQ) +#if defined(HAVE_LQ_TCP_INFO) || defined(HAVE_LQ_TCP_CONNECTION_INFO) || defined(HAVE_LQ_SO_LISTENQ) # define HAVE_FPM_LQ 1 #else # define HAVE_FPM_LQ 0 diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c index 003c62b7d05..e4b89f84565 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -524,6 +524,30 @@ int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) return 0; } +#elif defined(HAVE_LQ_TCP_CONNECTION_INFO) + +#include + +int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq) +{ + struct tcp_connection_info info; + socklen_t len = sizeof(info); + + if (0 > getsockopt(sock, IPPROTO_TCP, TCP_CONNECTION_INFO, &info, &len)) { + zlog(ZLOG_SYSERROR, "failed to retrieve TCP_CONNECTION_INFO for socket"); + return -1; + } + + if (cur_lq) { + *cur_lq = info.tcpi_tfo_syn_data_acked; + } + + if (max_lq) { + *max_lq = 0; + } + + return 0; +} #endif #ifdef HAVE_LQ_SO_LISTENQ