修正stream_write类型连接关闭处理中没有通知write_ctx的问题。

* 原实现处理stream_write连接的关闭事件时,没有将write_ctx中的引用指针置位。导致上层继续frag_write时,没有有效的底层连接。现修正。
This commit is contained in:
zhengchao
2018-11-20 16:42:35 +08:00
parent 67edf968f6
commit 811e8afcd6

View File

@@ -208,6 +208,11 @@ struct tfe_stream_write_ctx * tfe_stream_write_frag_start(const struct tfe_strea
int tfe_stream_write_frag(struct tfe_stream_write_ctx * w_ctx, const unsigned char * data, size_t size) int tfe_stream_write_frag(struct tfe_stream_write_ctx * w_ctx, const unsigned char * data, size_t size)
{ {
if(w_ctx->_stream == NULL)
{
return -EPIPE;
}
struct tfe_conn_private * this_conn = __this_conn(w_ctx->_stream, w_ctx->dir); struct tfe_conn_private * this_conn = __this_conn(w_ctx->_stream, w_ctx->dir);
int ret = 0; int ret = 0;
if (this_conn != NULL) if (this_conn != NULL)
@@ -224,8 +229,13 @@ int tfe_stream_write_frag(struct tfe_stream_write_ctx * w_ctx, const unsigned ch
void tfe_stream_write_frag_end(struct tfe_stream_write_ctx * w_ctx) void tfe_stream_write_frag_end(struct tfe_stream_write_ctx * w_ctx)
{ {
struct tfe_conn_private * this_conn = __this_conn(w_ctx->_stream, w_ctx->dir); struct tfe_conn_private * this_conn;
struct tfe_conn_private * peer_conn = __peer_conn(w_ctx->_stream, w_ctx->dir); struct tfe_conn_private * peer_conn;
/* The connection terminated before this function call */
if (w_ctx->_stream == NULL) goto __out;
this_conn = __this_conn(w_ctx->_stream, w_ctx->dir);
peer_conn = __peer_conn(w_ctx->_stream, w_ctx->dir);
if (this_conn != NULL) if (this_conn != NULL)
{ {
@@ -233,20 +243,18 @@ void tfe_stream_write_frag_end(struct tfe_stream_write_ctx * w_ctx)
bufferevent_enable(peer_conn->bev, EV_READ); bufferevent_enable(peer_conn->bev, EV_READ);
} }
if (w_ctx->_stream != NULL) if (w_ctx->dir == CONN_DIR_DOWNSTREAM)
{ {
if (w_ctx->dir == CONN_DIR_DOWNSTREAM) assert(w_ctx->_stream->w_ctx_downstream == w_ctx);
{ w_ctx->_stream->w_ctx_downstream = NULL;
assert(w_ctx->_stream->w_ctx_downstream == w_ctx); }
w_ctx->_stream->w_ctx_downstream = NULL; else
} {
else assert(w_ctx->_stream->w_ctx_upstream == w_ctx);
{ w_ctx->_stream->w_ctx_upstream = NULL;
assert(w_ctx->_stream->w_ctx_upstream == w_ctx);
w_ctx->_stream->w_ctx_upstream = NULL;
}
} }
__out:
free(w_ctx); free(w_ctx);
} }
@@ -616,6 +624,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void *
struct tfe_conn_private ** ref_peer_conn{}; struct tfe_conn_private ** ref_peer_conn{};
struct ssl_stream ** ref_this_ssl_stream{}; struct ssl_stream ** ref_this_ssl_stream{};
struct ssl_stream ** ref_peer_ssl_stream{}; struct ssl_stream ** ref_peer_ssl_stream{};
struct tfe_stream_write_ctx ** ref_this_write_ctx{};
const char * __str_dir = NULL; const char * __str_dir = NULL;
if (__bev_dir(_stream, bev) == CONN_DIR_UPSTREAM) if (__bev_dir(_stream, bev) == CONN_DIR_UPSTREAM)
@@ -624,6 +633,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void *
ref_peer_conn = &_stream->conn_downstream; ref_peer_conn = &_stream->conn_downstream;
ref_this_ssl_stream = &_stream->ssl_upstream; ref_this_ssl_stream = &_stream->ssl_upstream;
ref_peer_ssl_stream = &_stream->ssl_downstream; ref_peer_ssl_stream = &_stream->ssl_downstream;
ref_this_write_ctx = &_stream->w_ctx_upstream;
} }
if (__bev_dir(_stream, bev) == CONN_DIR_DOWNSTREAM) if (__bev_dir(_stream, bev) == CONN_DIR_DOWNSTREAM)
@@ -632,6 +642,7 @@ static void __stream_bev_eventcb(struct bufferevent * bev, short events, void *
ref_peer_conn = &_stream->conn_upstream; ref_peer_conn = &_stream->conn_upstream;
ref_this_ssl_stream = &_stream->ssl_downstream; ref_this_ssl_stream = &_stream->ssl_downstream;
ref_peer_ssl_stream = &_stream->ssl_upstream; ref_peer_ssl_stream = &_stream->ssl_upstream;
ref_this_write_ctx = &_stream->w_ctx_downstream;
} }
if (events & BEV_EVENT_ERROR || events & BEV_EVENT_EOF) if (events & BEV_EVENT_ERROR || events & BEV_EVENT_EOF)
@@ -665,6 +676,12 @@ __close_connection:
if (*ref_this_conn != NULL) if (*ref_this_conn != NULL)
{ {
/* There is a frag writter setted, need to clear the reference of stream in the writter to indicate the connection is closed */
if(*ref_this_write_ctx != NULL)
{
(*ref_this_write_ctx)->_stream = NULL;
}
__conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream); __conn_private_destory_with_ssl(ev_base, *ref_this_conn, *ref_this_ssl_stream);
*ref_this_conn = NULL; *ref_this_conn = NULL;
*ref_this_ssl_stream = NULL; *ref_this_ssl_stream = NULL;