Close #66 修正POP/IMAP等服务端首先发送数据的协议处理异常的问题

* 原实现在upstream连接成功时,立即使能了EV_READ事件。在downstream创建成功以前,无法正确转发upstream发来的数据;
* 现修正为,在upstream, downstream都创建成功时,再使能upstream, downstream的EV_READ事件。
This commit is contained in:
Lu Qiuwen
2018-11-04 16:51:09 +08:00
parent 668c1b3e52
commit adcd1640bf

View File

@@ -31,6 +31,7 @@
#include <tcp_stream.h>
#include <proxy.h>
#include <netinet/tcp.h>
#include <event2/bufferevent_struct.h>
#ifndef TFE_CONFIG_OUTPUT_LIMIT_DEFAULT
#define TFE_CONFIG_OUTPUT_LIMIT_DEFAULT (1024 * 1024)
@@ -265,8 +266,7 @@ static tfe_conn_private * __conn_private_create_by_bev(struct tfe_stream_private
__conn_private->fd = bufferevent_getfd(bev);
bufferevent_setcb(__conn_private->bev, __stream_bev_readcb, __stream_bev_writecb, __stream_bev_eventcb, stream);
bufferevent_enable(__conn_private->bev, EV_READ | EV_WRITE);
bufferevent_disable(__conn_private->bev, EV_READ | EV_WRITE);
return __conn_private;
}
@@ -691,6 +691,7 @@ static tfe_conn_private * __conn_private_create_by_fd(struct tfe_stream_private
__conn_private->bev = bufferevent_socket_new(__ev_base, fd, BEV_OPT_DEFER_CALLBACKS);
__conn_private->fd = fd;
struct bufferevent * __bev = __conn_private->bev;
if (!__conn_private->bev)
{
TFE_LOG_ERROR(__STREAM_LOGGER(stream), "Failed at creating bufferevent for fd %d", fd);
@@ -708,6 +709,7 @@ static tfe_conn_private * __conn_private_create_by_fd(struct tfe_stream_private
__stream_bev_writecb, __stream_bev_eventcb, stream);
}
bufferevent_disable(__conn_private->bev, EV_READ | EV_WRITE);
return __conn_private;
__errout:
@@ -746,7 +748,8 @@ void ssl_downstream_create_on_fail(enum e_future_error err, const char * what, v
struct tfe_stream_private * _stream = (struct tfe_stream_private *) user;
assert(_stream != NULL && _stream->session_type == STREAM_PROTO_SSL);
TFE_STREAM_LOG_ERROR(_stream, "Failed to create SSL downstream, close the connection : %s. ", what);
TFE_STREAM_LOG_ERROR(_stream, "%s - Failed to create SSL downstream, close the connection : %s. ",
_stream->str_stream_addr, what);
/* There is nothing we can do because upstream has been handshake,
* Close the stream */
@@ -786,8 +789,10 @@ void ssl_upstream_create_on_fail(enum e_future_error err, const char * what, voi
struct tfe_stream_private * _stream = (struct tfe_stream_private *) user;
assert(_stream != NULL && _stream->session_type == STREAM_PROTO_SSL);
TFE_STREAM_LOG_ERROR(_stream, "Failed to create SSL upstream, pass-through the connection : %s. ", what);
TFE_STREAM_LOG_ERROR(_stream, "%s - Failed to create SSL upstream, pass-through the connection : %s. ",
_stream->str_stream_addr, what);
_stream->passthough = true;
_stream->conn_downstream = __conn_private_create_by_fd(_stream, _stream->defer_fd_downstream);
_stream->conn_upstream = __conn_private_create_by_fd(_stream, _stream->defer_fd_downstream);