增加读入USER_TIMEOUT TCP选项,修正timeout相关的setsockopt设置。

This commit is contained in:
Lu Qiuwen
2018-09-21 19:06:44 +08:00
parent 1a70d3948a
commit 7b6dbb06aa
8 changed files with 22 additions and 10 deletions

View File

@@ -98,4 +98,4 @@ int tfe_stream_shutdown_dir(const struct tfe_stream * stream, enum tfe_conn_dir
/** /**
* @brief Write linear text for given stream * @brief Write linear text for given stream
*/ */
void tfe_stream_write_log(const struct tfe_stream * stream, int level, const char * fmt, ...); void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...);

View File

@@ -155,7 +155,7 @@ static inline char * tfe_stream_addr_to_str(const struct tfe_stream_addr * addr)
inet_ntop(AF_INET, &tuple4_v4->saddr, __src_addr, sizeof(__src_addr)); inet_ntop(AF_INET, &tuple4_v4->saddr, __src_addr, sizeof(__src_addr));
inet_ntop(AF_INET, &tuple4_v4->daddr, __dst_addr, sizeof(__dst_addr)); inet_ntop(AF_INET, &tuple4_v4->daddr, __dst_addr, sizeof(__dst_addr));
asprintf(&__str_ret, "%s %s %u %u", __src_addr, __dst_addr, __src_port, __dst_port); asprintf(&__str_ret, "%s %u %s %u", __src_addr, __src_port, __dst_addr, __dst_port);
} }
if(addr->addrtype == TFE_ADDR_STREAM_TUPLE4_V6) if(addr->addrtype == TFE_ADDR_STREAM_TUPLE4_V6)

View File

@@ -18,7 +18,7 @@ TEST(TfeStreamAddrToStr, StreamTuple4)
st_addr_v4->daddr.s_addr = 0x6464a8c0; st_addr_v4->daddr.s_addr = 0x6464a8c0;
st_addr_v4->dest = 20480; st_addr_v4->dest = 20480;
const char * __sample = "192.168.100.50 192.168.100.100 10080 80"; const char * __sample = "192.168.100.50 10080 192.168.100.100 80";
char * __result = tfe_stream_addr_to_str(__stream_addr); char * __result = tfe_stream_addr_to_str(__stream_addr);
EXPECT_STREQ(__sample, __result); EXPECT_STREQ(__sample, __result);

View File

@@ -16,6 +16,7 @@ struct tfe_proxy_tcp_options
int tcp_keepidle; int tcp_keepidle;
int tcp_keepintvl; int tcp_keepintvl;
int tcp_keepcnt; int tcp_keepcnt;
int tcp_user_timeout;
}; };
struct tfe_proxy_accept_para struct tfe_proxy_accept_para

View File

@@ -193,6 +193,7 @@ int tfe_proxy_config(struct tfe_proxy * proxy, const char * profile)
MESA_load_profile_int_def(profile, "tcp", "tcp_keepidle", &proxy->tcp_options.tcp_keepidle, -1); MESA_load_profile_int_def(profile, "tcp", "tcp_keepidle", &proxy->tcp_options.tcp_keepidle, -1);
MESA_load_profile_int_def(profile, "tcp", "tcp_keepintvl", &proxy->tcp_options.tcp_keepintvl, -1); MESA_load_profile_int_def(profile, "tcp", "tcp_keepintvl", &proxy->tcp_options.tcp_keepintvl, -1);
MESA_load_profile_int_def(profile, "tcp", "tcp_keepcnt", &proxy->tcp_options.tcp_keepcnt, -1); MESA_load_profile_int_def(profile, "tcp", "tcp_keepcnt", &proxy->tcp_options.tcp_keepcnt, -1);
MESA_load_profile_int_def(profile, "tcp", "tcp_user_timeout", &proxy->tcp_options.tcp_user_timeout, -1);
return 0; return 0;
} }

View File

@@ -67,7 +67,7 @@ static inline enum tfe_conn_dir __bev_dir(struct tfe_stream_private * _stream, s
return CONN_DIR_DOWNSTREAM; return CONN_DIR_DOWNSTREAM;
} }
if(_stream->conn_upstream && bev == _stream->conn_upstream->bev) if (_stream->conn_upstream && bev == _stream->conn_upstream->bev)
{ {
return CONN_DIR_UPSTREAM; return CONN_DIR_UPSTREAM;
} }
@@ -840,7 +840,7 @@ void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket
if (tcp_options->tcp_keepcnt > 0) if (tcp_options->tcp_keepcnt > 0)
{ {
if (setsockopt(fd, SOL_SOCKET, TCP_KEEPCNT, (const void *) &tcp_options->tcp_keepcnt, sizeof(int)) == -1) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, (const void *) &tcp_options->tcp_keepcnt, sizeof(int)) == -1)
{ {
TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_KEEPCNT, %d) failed, ignored: %s", TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_KEEPCNT, %d) failed, ignored: %s",
tcp_options->tcp_keepcnt, strerror(errno)); tcp_options->tcp_keepcnt, strerror(errno));
@@ -849,7 +849,7 @@ void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket
if (tcp_options->tcp_keepintvl > 0) if (tcp_options->tcp_keepintvl > 0)
{ {
if (setsockopt(fd, SOL_SOCKET, TCP_KEEPINTVL, (const void *) &tcp_options->tcp_keepintvl, sizeof(int)) == -1) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, (const void *) &tcp_options->tcp_keepintvl, sizeof(int)) == -1)
{ {
TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_KEEPINTVL, %d) failed, ignored: %s", TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_KEEPINTVL, %d) failed, ignored: %s",
tcp_options->tcp_keepintvl, strerror(errno)); tcp_options->tcp_keepintvl, strerror(errno));
@@ -858,13 +858,23 @@ void __stream_fd_option_setup(struct tfe_stream_private * _stream, evutil_socket
if (tcp_options->tcp_keepidle > 0) if (tcp_options->tcp_keepidle > 0)
{ {
if (setsockopt(fd, SOL_SOCKET, TCP_KEEPIDLE, (const void *) &tcp_options->tcp_keepidle, sizeof(int)) == -1) if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, (const void *) &tcp_options->tcp_keepidle, sizeof(int)) == -1)
{ {
TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_KEEPIDLE, %d) failed, ignored: %s", TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_KEEPIDLE, %d) failed, ignored: %s",
tcp_options->tcp_keepidle, strerror(errno)); tcp_options->tcp_keepidle, strerror(errno));
} }
} }
if (tcp_options->tcp_user_timeout > 0)
{
if (setsockopt(fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (const void *) &tcp_options->tcp_user_timeout, sizeof(int))
== -1)
{
TFE_STREAM_LOG_ERROR(stream, "setsockopt(TCP_USER_TIMEOUT, %d) failed, ignored: %s",
tcp_options->tcp_user_timeout, strerror(errno));
}
}
return; return;
} }
@@ -932,7 +942,7 @@ int tfe_stream_option_set(struct tfe_stream * stream, enum tfe_stream_option opt
return 0; return 0;
} }
void tfe_stream_write_log(const struct tfe_stream * stream, int level, const char * fmt, ...) void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...)
{ {
va_list arg_ptr; va_list arg_ptr;
va_start(arg_ptr, fmt); va_start(arg_ptr, fmt);

View File

@@ -584,7 +584,7 @@ void __write_access_log(struct http_session_private * hs_private)
__offset += snprintf(__access_log + __offset, sizeof(__access_log) - __offset, "%s ", __str_url); __offset += snprintf(__access_log + __offset, sizeof(__access_log) - __offset, "%s ", __str_url);
const struct tfe_stream * stream = hs_private->hc_private->stream; const struct tfe_stream * stream = hs_private->hc_private->stream;
tfe_stream_write_log(stream, RLOG_LV_INFO, "%s", __access_log); tfe_stream_write_access_log(stream, RLOG_LV_INFO, "%s", __access_log);
(void)resp_spec; (void)resp_spec;
} }

View File

@@ -444,7 +444,7 @@ TEST(HttpHalfConstructCallback, PostWithBody)
EXPECT_TRUE(ctx->req_end_called); EXPECT_TRUE(ctx->req_end_called);
} }
void tfe_stream_write_log(const struct tfe_stream * stream, int level, const char * fmt, ...) void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...)
{ {
return; return;
} }