From 4c0b732a0f0d2295707542677cead3313c2a1a0f Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Tue, 10 Aug 2021 15:17:42 +0800 Subject: bugfix: TSG-7333 Proxy使用ssl_stream_log_error打印错误日志时频繁调用asprintf()/free()拼接四元组字符串 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platform/src/ssl_stream.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'platform/src/ssl_stream.cpp') diff --git a/platform/src/ssl_stream.cpp b/platform/src/ssl_stream.cpp index 865e623..55f3924 100644 --- a/platform/src/ssl_stream.cpp +++ b/platform/src/ssl_stream.cpp @@ -1083,11 +1083,10 @@ static void ssl_stream_set_cmsg_integer(struct ssl_stream* stream, enum tfe_cmsg return; } -unsigned long ssl_stream_log_error(struct bufferevent * bev, enum tfe_conn_dir dir, struct ssl_mgr* mgr) +unsigned long ssl_stream_log_error(struct bufferevent * bev, enum tfe_conn_dir dir, struct ssl_mgr* mgr, const char *addr) { unsigned long sslerr=0, ret_sslerr=0; int fd=bufferevent_getfd(bev); - char* addr_string=tfe_string_addr_create_by_fd(fd, dir); void* logger=mgr->logger; int fs_id=-1; @@ -1134,7 +1133,7 @@ unsigned long ssl_stream_log_error(struct bufferevent * bev, enum tfe_conn_dir d TFE_LOG_ERROR(logger,"Handshake Error from bufferevent of ssl %s %s: " "%i:%s %lu:%i:%s:%i:%s:%i:%s", tfe_stream_conn_dir_to_str(dir), - addr_string, + addr, errno, errno ? strerror(errno) : "-", sslerr, @@ -1168,7 +1167,7 @@ unsigned long ssl_stream_log_error(struct bufferevent * bev, enum tfe_conn_dir d TFE_LOG_ERROR(logger,"Error from bufferevent of ssl %s %s: " "%i:%s %lu:%i:%s:%i:%s:%i:%s", tfe_stream_conn_dir_to_str(dir), - addr_string, + addr, errno, errno ? strerror(errno) : "-", sslerr, @@ -1196,7 +1195,6 @@ unsigned long ssl_stream_log_error(struct bufferevent * bev, enum tfe_conn_dir d ERR_func_error_string(sslerr)); } } - free(addr_string); return ret_sslerr; } void ssl_stream_process_error(struct ssl_stream * s_stream, unsigned long sslerr, struct ssl_mgr* mgr) @@ -1283,7 +1281,7 @@ static void ssl_server_connected_eventcb(struct bufferevent * bev, short events, if (events & BEV_EVENT_ERROR) { ATOMIC_INC(&(ctx->mgr->stat_val[SSL_UP_ERR])); - sslerr=ssl_stream_log_error(bev, CONN_DIR_UPSTREAM, ctx->mgr); + sslerr=ssl_stream_log_error(bev, CONN_DIR_UPSTREAM, ctx->mgr, s_stream->tcp_stream->str_stream_info); if(sslerr) { ssl_stream_process_error(s_stream, sslerr, mgr); @@ -1898,7 +1896,7 @@ static void ssl_client_connected_eventcb(struct bufferevent * bev, short events, if (events & BEV_EVENT_ERROR) { ATOMIC_INC(&(mgr->stat_val[SSL_DOWN_ERR])); - sslerr=ssl_stream_log_error(bev, CONN_DIR_DOWNSTREAM, mgr); + sslerr=ssl_stream_log_error(bev, CONN_DIR_DOWNSTREAM, mgr, s_stream->tcp_stream->str_stream_info); if(sslerr) { ssl_stream_process_error(s_stream, sslerr, mgr); @@ -2046,7 +2044,7 @@ void ssl_stream_free(struct ssl_stream * s_stream, struct event_base * evbase, s if(errno) { - sslerr=ssl_stream_log_error(bev, s_stream->dir, s_stream->mgr); + sslerr=ssl_stream_log_error(bev, s_stream->dir, s_stream->mgr, s_stream->tcp_stream->str_stream_info); if(sslerr) { ssl_stream_process_error(s_stream, sslerr, s_stream->mgr); -- cgit v1.2.3