acl_threads_server can bind unix domain socket when using SO_REUSEPORT.

This commit is contained in:
zhengshuxin 2022-09-14 14:53:13 +08:00
parent 8fea051a7f
commit 837e373a4c
6 changed files with 55 additions and 9 deletions

View File

@ -109,7 +109,7 @@ endif
##############################################################################
.PHONY = check help all_lib all samples all clean install uninstall uninstall_all build_one
VERSION = 3.5.3-21
VERSION = 3.5.3-22
default: build_one acl_master
help h:

View File

@ -25,7 +25,7 @@
#include "init.h"
static char *version = "3.5.3-21 20220831-15:18";
static char *version = "3.5.3-22 20220914-14:50";
const char *acl_version(void)
{

View File

@ -123,9 +123,9 @@ char *acl_var_aio_event_mode;
char *acl_var_aio_pid_dir;
char *acl_var_aio_access_allow;
char *acl_var_aio_accept_alone;
char *acl_var_aio_log_debug;
char *acl_var_aio_dispatch_addr;
char *acl_var_aio_dispatch_type;
char *acl_var_aio_log_debug;
char *acl_var_aio_deny_info;
static ACL_CONFIG_STR_TABLE __conf_str_tab[] = {
@ -135,9 +135,10 @@ static ACL_CONFIG_STR_TABLE __conf_str_tab[] = {
{ "aio_access_allow", "0.0.0.0:255.255.255.255", &acl_var_aio_access_allow },
{ "aio_event_mode", "select", &acl_var_aio_event_mode },
{ "aio_accept_alone", "yes", &acl_var_aio_accept_alone },
{ "master_debug", "", &acl_var_aio_log_debug },
{ "aio_dispatch_addr", "", &acl_var_aio_dispatch_addr },
{ "aio_dispatch_type", "default", &acl_var_aio_dispatch_type },
{ "master_debug", "", &acl_var_aio_log_debug },
{ "master_deny_info", "you're not welcome!", &acl_var_aio_deny_info },
{ 0, 0, 0 },

View File

@ -138,6 +138,7 @@ char *acl_var_threads_dispatch_addr;
char *acl_var_threads_dispatch_type;
char *acl_var_threads_master_service;
char *acl_var_threads_master_reuseport;
char *acl_var_threads_master_private;
static int var_threads_master_reuseport = 0;
@ -149,13 +150,15 @@ static ACL_CONFIG_STR_TABLE __conf_str_tab[] = {
#else
{ "ioctl_event_mode", "select", &acl_var_threads_event_mode },
#endif
{ "master_debug", "", &acl_var_threads_log_debug },
{ "ioctl_deny_banner", "You'are not Welcome!", &acl_var_threads_deny_banner },
{ "ioctl_access_allow", "all", &acl_var_threads_access_allow },
{ "ioctl_dispatch_addr", "", &acl_var_threads_dispatch_addr },
{ "ioctl_dispatch_type", "default", &acl_var_threads_dispatch_type },
{ "master_debug", "", &acl_var_threads_log_debug },
{ "master_service", "", &acl_var_threads_master_service },
{ "master_reuseport", "", &acl_var_threads_master_reuseport },
{ "master_private", "n", &acl_var_threads_master_private },
{ 0, 0, 0 },
};
@ -1243,6 +1246,40 @@ static ACL_VSTREAM **server_daemon_open(ACL_EVENT *event,
#endif
static int is_ipaddr(const char *addr)
{
// Just only the port, such as: 8088
if (acl_alldig(addr)) {
return 1;
}
// Such as: ip:port, or ip|port, or :port, or |port
if (strrchr(addr, ':') || strrchr(addr, ACL_ADDR_SEP)) {
return 1;
}
if (acl_valid_ipv6_hostaddr(addr, 0) || acl_valid_ipv4_hostaddr(addr, 0)) {
return 1;
}
return 0;
}
static void correct_addr(const char *addr, char *buf, size_t size)
{
if (is_ipaddr(addr)) {
ACL_SAFE_STRNCPY(buf, addr, size);
} else {
const char *pri = !strcmp(acl_var_threads_master_private, "y") ?
"private" : "public";
#if defined(_WIN32) || defined(_WIN64)
_snprintf(buf, size, "%s/%s/%s", acl_var_thread_queue_dir, pri, addr);
#else
snprintf(buf, size, "%s/%s/%s", acl_var_threads_queue_dir, pri, addr);
#endif
}
}
static ACL_VSTREAM **server_alone_open(ACL_EVENT *event,
acl_pthread_pool_t *threads, const char *addrs)
{
@ -1265,11 +1302,14 @@ static ACL_VSTREAM **server_alone_open(ACL_EVENT *event,
i = 0;
acl_foreach(iter, tokens) {
const char* addr = (const char*) iter.data;
ACL_VSTREAM* sstream = acl_vstream_listen_ex(addr, 128,
char addrbuf[512];
correct_addr(addr, addrbuf, sizeof(addrbuf));
ACL_VSTREAM* sstream = acl_vstream_listen_ex(addrbuf, 128,
flag, 0, 0);
if (sstream == NULL) {
acl_msg_error("%s(%d): listen %s error(%s)",
myname, __LINE__, addr, acl_last_serror());
myname, __LINE__, addrbuf, acl_last_serror());
exit(2);
}

View File

@ -845,7 +845,8 @@ static void server_open(FIBER_SERVER *server, ACL_ARGV *addrs)
acl_foreach(iter, addrs) {
const char* addr = (const char*) iter.data;
char addrbuf[256];
char addrbuf[512];
correct_addr(addr, addrbuf, sizeof(addrbuf));
ACL_VSTREAM* sstream = acl_vstream_listen_ex(addrbuf, 128,
flag, 0, 0);

View File

@ -1,4 +1,4 @@
%define release_id 21
%define release_id 22
Summary: The powerful c/c++ library
Name: acl-libs
@ -45,6 +45,10 @@ rm -rf %{buildroot}
%changelog
* Wed Sep 14 2022 shuxin.zheng shuxin.zheng@qq.com 3.5.3-22-20220914.14
- bugfix: when using SO_REUSEPORT, acl_threads_server.cpp should support
binding unix domain socket.
* Wed Aug 31 2022 shuxin.zheng shuxin.zheng@qq.com 3.5.3-21-20220821.15
- feature: Openssl has been supported in acl ssl module
- workaroud: when IO timeout be set 0, which will not block the IO process,