@@ -54,8 +54,8 @@ void manapi::net::worker::TLS::close_connection(shared_conn conn, int flags) MAN
5454 if (!conn)
5555 return ;
5656
57- this ->waiting (conn, true );
5857 auto const connection = conn->as <tls_connection_t >();
58+ bool keep_alive_disabled;
5959
6060 if (connection->flags & CONN_REMOVED)
6161 return ;
@@ -69,23 +69,33 @@ void manapi::net::worker::TLS::close_connection(shared_conn conn, int flags) MAN
6969 return ;
7070 }
7171
72+ /* Draining timeout is enabled, thus, connection is draining */
73+ if (flags & CLOSE_CONN_EOR || flags & CLOSE_CONN_EOS) {
74+ conn->wrk .flags |= WRK_INTERFACE_IS_DRAINING;
75+ }
76+
77+ if ((flags & CLOSE_CONN_EOR)) {
78+ connection->flags |= CONN_RECV_END;
79+
80+ if (connection->flags == CLOSE_CONN_EOR) {
81+ if (!connection->t && !(connection->flags & CONN_READ)) {
82+ return ;
83+ }
84+ }
85+ }
86+
87+ this ->waiting (conn, true );
7288 connection->flags |= CONN_TLS_SHUTDOWN;
7389
74- if (!this ->config_ ->force_conn_shutdown
75- && (
76- (flags & (CLOSE_CONN_SHUTDOWN|CLOSE_CONN_ERR))
77- || (!flags
78- && (!this ->config_ ->keep_alive
79- || !(conn->wrk .flags & WRK_INTERFACE_TCP_KEEP_ALIVE)
80- )
81- ))) {
90+ keep_alive_disabled = (!this ->config_ ->keep_alive || !(conn->wrk .flags & WRK_INTERFACE_TCP_KEEP_ALIVE));
91+ if (!this ->config_ ->force_conn_shutdown && ((flags & (CLOSE_CONN_SHUTDOWN|CLOSE_CONN_ERR)) || (!flags && keep_alive_disabled))) {
8292
8393 if (conn->wrk .flags & WRK_INTERFACE_TCP_KEEP_ALIVE)
8494 conn->wrk .flags ^= WRK_INTERFACE_TCP_KEEP_ALIVE;
8595
8696 if (connection->ev_callback ) {
8797 auto cb = std::move (connection->ev_callback );
88- if (this -> call_user_callback (&cb, conn, ev::DISCONNECT, nullptr , 0 , nullptr )) {
98+ if (manapi::net::worker::TLS:: call_user_callback (&cb, conn, ev::DISCONNECT, nullptr , 0 , nullptr )) {
8999 /* skip */
90100 }
91101 }
@@ -99,10 +109,13 @@ void manapi::net::worker::TLS::close_connection(shared_conn conn, int flags) MAN
99109
100110 eof:
101111 if (flags & (CLOSE_CONN_EOR|CLOSE_CONN_EOS)) {
112+ manapi_log_trace (manapi::debug::LOG_TRACE_LOW, " TLS:conn %p was destroyed "
113+ " CLOSE_CONN_EOR=%d CLOSE_CONN_EOS=%d" , conn.get (),
114+ CLOSE_CONN_EOR & flags, CLOSE_CONN_EOS & flags);
102115 this ->ssl_set_shutdown_ (connection->ssl ,
103116 this ->ssl_recv_shutdown_ |this ->ssl_send_shutdown_ );
104117 /* connection is destroyed */
105- flags |= CLOSE_CONN_FINISHED ;
118+ flags |= CLOSE_CONN_SHUTDOWN ;
106119 }
107120 //
108121 // if (connection->accept_timer) {
0 commit comments