mirror of https://github.com/F-Stack/f-stack.git
Nginx : add a creation flag SOCK_FSTACK(create-fstack-socket) for socket()
1. `#define SOCK_FSTACK 0x1000` 2. when we want to create socket by fstack, we code like this : `s = ngx_socket(domain, type | SOCK_FSTACK , protocol);`
This commit is contained in:
parent
edbcaf6eef
commit
76e16b226f
|
@ -58,6 +58,7 @@ fi
|
||||||
if [ $USE_FSTACK = YES ]; then
|
if [ $USE_FSTACK = YES ]; then
|
||||||
have=NGX_HAVE_FSTACK . auto/have
|
have=NGX_HAVE_FSTACK . auto/have
|
||||||
have=NGX_HAVE_FSTACK . auto/have_headers
|
have=NGX_HAVE_FSTACK . auto/have_headers
|
||||||
|
have=SOCK_FSTACK value=0x1000 . auto/define
|
||||||
CORE_SRCS="$CORE_SRCS $KQUEUE_SRCS"
|
CORE_SRCS="$CORE_SRCS $KQUEUE_SRCS"
|
||||||
EVENT_MODULES="$EVENT_MODULES $KQUEUE_MODULE"
|
EVENT_MODULES="$EVENT_MODULES $KQUEUE_MODULE"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -15,7 +15,7 @@ extern int fstack_territory(int domain, int type, int protocol);
|
||||||
extern int is_fstack_fd(int sockfd);
|
extern int is_fstack_fd(int sockfd);
|
||||||
|
|
||||||
static ngx_inline int
|
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) {
|
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)) {
|
if (!fstack_territory(ls->sockaddr->sa_family, ls->type, 0)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ls->type |= SOCK_FSTACK;
|
||||||
} else {
|
} else {
|
||||||
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
|
||||||
"unexpected process type: %d, ignored",
|
"unexpected process type: %d, ignored",
|
||||||
|
|
|
@ -72,6 +72,7 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <ngx_auto_config.h>
|
||||||
#include "ff_api.h"
|
#include "ff_api.h"
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
@ -208,11 +209,16 @@ ff_mod_init(const char *conf, int proc_id, int proc_type) {
|
||||||
int
|
int
|
||||||
fstack_territory(int domain, int type, int protocol)
|
fstack_territory(int domain, int type, int protocol)
|
||||||
{
|
{
|
||||||
if ((AF_INET != domain) || (SOCK_STREAM != type && SOCK_DGRAM != type)) {
|
/* Remove creation flags */
|
||||||
return 0;
|
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
|
int
|
||||||
|
@ -223,10 +229,15 @@ socket(int domain, int type, int protocol)
|
||||||
return SYSCALL(socket)(domain, type, 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);
|
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);
|
sock = ff_socket(domain, type, protocol);
|
||||||
|
|
||||||
if (sock != -1) {
|
if (sock != -1) {
|
||||||
|
|
|
@ -39,23 +39,18 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc)
|
||||||
type = (pc->type ? pc->type : SOCK_STREAM);
|
type = (pc->type ? pc->type : SOCK_STREAM);
|
||||||
|
|
||||||
#if (NGX_HAVE_FSTACK)
|
#if (NGX_HAVE_FSTACK)
|
||||||
/*
|
/*
|
||||||
We need to explicitly call the needed socket() function
|
We use a creation flags created by fstack's adaptable layer to
|
||||||
to create socket!
|
to explicitly call the needed socket() function.
|
||||||
*/
|
*/
|
||||||
static int (*real_socket)(int, int, int);
|
if (!pc->belong_to_host) {
|
||||||
if (pc->belong_to_host) {
|
type |= SOCK_FSTACK;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
s = ngx_socket(pc->sockaddr->sa_family, type, 0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
s = ngx_socket(pc->sockaddr->sa_family, type, 0);
|
||||||
|
|
||||||
|
|
||||||
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, "%s socket %d",
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, "%s socket %d",
|
||||||
(type == SOCK_STREAM) ? "stream" : "dgram", s);
|
(type == SOCK_STREAM) ? "stream" : "dgram", s);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue