diff --git a/app/nginx-1.11.10/auto/modules b/app/nginx-1.11.10/auto/modules index 61051ee40..116ac7e84 100644 --- a/app/nginx-1.11.10/auto/modules +++ b/app/nginx-1.11.10/auto/modules @@ -58,6 +58,7 @@ fi if [ $USE_FSTACK = YES ]; then have=NGX_HAVE_FSTACK . auto/have have=NGX_HAVE_FSTACK . auto/have_headers + have=SOCK_FSTACK value=0x1000 . auto/define CORE_SRCS="$CORE_SRCS $KQUEUE_SRCS" EVENT_MODULES="$EVENT_MODULES $KQUEUE_MODULE" fi diff --git a/app/nginx-1.11.10/src/core/ngx_connection.c b/app/nginx-1.11.10/src/core/ngx_connection.c index 47e29ba43..46c0ebc03 100644 --- a/app/nginx-1.11.10/src/core/ngx_connection.c +++ b/app/nginx-1.11.10/src/core/ngx_connection.c @@ -15,7 +15,7 @@ extern int fstack_territory(int domain, int type, int protocol); extern int is_fstack_fd(int sockfd); static ngx_inline int -ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, const ngx_listening_t *ls) +ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, ngx_listening_t *ls) { if (ngx_process <= NGX_PROCESS_MASTER) { @@ -36,6 +36,8 @@ ngx_ff_skip_listening_socket(ngx_cycle_t *cycle, const ngx_listening_t *ls) if (!fstack_territory(ls->sockaddr->sa_family, ls->type, 0)) { return 1; } + + ls->type |= SOCK_FSTACK; } else { ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unexpected process type: %d, ignored", diff --git a/app/nginx-1.11.10/src/event/modules/ngx_ff_module.c b/app/nginx-1.11.10/src/event/modules/ngx_ff_module.c index 75bd3de44..0bef51773 100644 --- a/app/nginx-1.11.10/src/event/modules/ngx_ff_module.c +++ b/app/nginx-1.11.10/src/event/modules/ngx_ff_module.c @@ -72,6 +72,7 @@ #include #include +#include #include "ff_api.h" #define _GNU_SOURCE @@ -208,11 +209,16 @@ ff_mod_init(const char *conf, int proc_id, int proc_type) { int fstack_territory(int domain, int type, int protocol) { - if ((AF_INET != domain) || (SOCK_STREAM != type && SOCK_DGRAM != type)) { - return 0; - } + /* Remove creation flags */ + type &= ~SOCK_CLOEXEC; + type &= ~SOCK_NONBLOCK; + type &= ~SOCK_FSTACK; - return 1; + if ((AF_INET != domain) || (SOCK_STREAM != type && SOCK_DGRAM != type)) { + return 0; + } + + return 1; } int @@ -223,10 +229,15 @@ socket(int domain, int type, int protocol) return SYSCALL(socket)(domain, type, protocol); } - if ((AF_INET != domain) || (SOCK_STREAM != type && SOCK_DGRAM != type)) { + if (unlikely(fstack_territory(domain, type, protocol) == 0)) { return SYSCALL(socket)(domain, type, protocol); } + if (unlikely((type & SOCK_FSTACK) == 0)) { + return SYSCALL(socket)(domain, type, protocol); + } + + type &= ~SOCK_FSTACK; sock = ff_socket(domain, type, protocol); if (sock != -1) { diff --git a/app/nginx-1.11.10/src/event/ngx_event_connect.c b/app/nginx-1.11.10/src/event/ngx_event_connect.c index 09cd2340b..4343340cd 100644 --- a/app/nginx-1.11.10/src/event/ngx_event_connect.c +++ b/app/nginx-1.11.10/src/event/ngx_event_connect.c @@ -39,23 +39,18 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc) type = (pc->type ? pc->type : SOCK_STREAM); #if (NGX_HAVE_FSTACK) - /* - We need to explicitly call the needed socket() function - to create socket! + /* + We use a creation flags created by fstack's adaptable layer to + to explicitly call the needed socket() function. */ - static int (*real_socket)(int, int, int); - if (pc->belong_to_host) { - if (!real_socket) { - real_socket = dlsym(RTLD_NEXT, "socket"); - } - s = real_socket(pc->sockaddr->sa_family, type, 0); - } else { - s = ngx_socket(pc->sockaddr->sa_family, type, 0); + if (!pc->belong_to_host) { + type |= SOCK_FSTACK; } -#else - s = ngx_socket(pc->sockaddr->sa_family, type, 0); #endif + s = ngx_socket(pc->sockaddr->sa_family, type, 0); + + ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, "%s socket %d", (type == SOCK_STREAM) ? "stream" : "dgram", s);