2121struct ssl_bio_deleter_t ;
2222
2323enum conn_tls_flags {
24- CONN_TLS_SHUTDOWN = manapi::net::worker::base::CONN_MAX_CODE * 2 ,
25- CONN_TLS_EARLY_DATA = CONN_TLS_SHUTDOWN * 2 ,
26- CONN_TLS_EARLY_FINISHED = CONN_TLS_EARLY_DATA * 2
24+ CONN_TLS_SHUTDOWN = manapi::net::worker::base::CONN_MAX_CODE << 1 ,
25+ CONN_TLS_EARLY_DATA = CONN_TLS_SHUTDOWN << 1 ,
26+ CONN_TLS_EARLY_FINISHED = CONN_TLS_EARLY_DATA<< 1
2727};
2828
2929manapi::net::worker::TLS::TLS (net::http::site site, std::shared_ptr<multithread_storage::worker_t > wdata, manapi::net::http::config *config) : TCP(std::move(site), std::move(wdata), config) {}
@@ -77,6 +77,8 @@ void manapi::net::worker::TLS::close_connection(shared_conn conn, int flags) MAN
7777 )
7878 ))) {
7979
80+ assert (!(flags & CLOSE_CONN_ERR));
81+
8082 if (conn->wrk .flags & WRK_INTERFACE_TCP_KEEP_ALIVE)
8183 conn->wrk .flags ^= WRK_INTERFACE_TCP_KEEP_ALIVE;
8284
@@ -98,12 +100,12 @@ void manapi::net::worker::TLS::close_connection(shared_conn conn, int flags) MAN
98100 if (flags & CLOSE_CONN_EOF)
99101 this ->ssl_set_shutdown_ (connection->ssl ,
100102 this ->ssl_recv_shutdown_ |this ->ssl_send_shutdown_ );
101-
102- if (connection->accept_timer ) {
103- prepared::timer_clear (std::move (connection->accept_timer ));
104-
105- flags = CLOSE_CONN_EOF;
106- }
103+ //
104+ // if (connection->accept_timer) {
105+ // prepared::timer_clear(std::move(connection->accept_timer));
106+ //
107+ // flags = CLOSE_CONN_EOF;
108+ // }
107109
108110 TCP::close_connection (conn, flags);
109111
@@ -275,7 +277,7 @@ void manapi::net::worker::TLS::update_limit_rate_connection(const shared_conn &s
275277
276278 this ->read_start_ (data);
277279
278- if (!(data->flags & ev::DISCONNECT) && data->flags & ev::WRITE && data->ev_callback ) {
280+ if (!(data->flags & ev::DISCONNECT) && ( data->flags & ev::WRITE) && data->ev_callback ) {
279281 if (manapi::net::worker::base::call_user_callback (&data->ev_callback , sconn, ev::WRITE, nullptr , 0 , nullptr )) {
280282 this ->close_connection (sconn, CLOSE_CONN_ERR);
281283 return ;
@@ -351,8 +353,8 @@ void manapi::net::worker::TLS::shutdown_async_(shared_conn conn) {
351353 if (s->accept_timer ) {
352354 s->accept_timer .stop ();
353355 s->accept_timer = nullptr ;
354-
355356 }
357+
356358 auto accept_timer_res = manapi::async::current ()->timerpool ()->append_timer_sync (5000 , [wconn = std::weak_ptr (conn)] (manapi::timer t)
357359 -> void { auto conn = wconn.lock (); if (conn) { auto w = conn->as <tcp_connection_t >(); w->worker ->close_connection (conn, CLOSE_CONN_EOF); } });
358360 if (accept_timer_res)
@@ -367,7 +369,9 @@ void manapi::net::worker::TLS::shutdown_async_(shared_conn conn) {
367369 auto rhs = this ->ssl_shutdown_ (s->ssl );
368370 manapi_log_trace (debug::LOG_TRACE_LOW, " TLS:Shutdown %p = %d" , s, rhs);
369371
372+
370373 if (!rhs) {
374+ this ->read_start_ (s);
371375 goto write;
372376 }
373377
@@ -454,10 +458,13 @@ void manapi::net::worker::TLS::onrecv(const std::shared_ptr<ev::tcp> &watcher, c
454458 this ->read_stop_ (data);
455459 }
456460
461+ manapi_log_trace_hard (" TLS:recv %p flags=%d size=%zu" , data, data->flags , buffer.size ());
462+
457463 while (size) {
458464 auto rhs = this ->ssl_bio_write_ (data->rbio , buff, static_cast <int >(size));
459465 if (rhs <= 0 ) {
460466 /* error */
467+ data->flags |= ev::DISCONNECT;
461468 goto err;
462469 }
463470
@@ -466,6 +473,10 @@ void manapi::net::worker::TLS::onrecv(const std::shared_ptr<ev::tcp> &watcher, c
466473
467474 /* TODO: resolve this dump logic */
468475
476+ if (data->flags & CONN_TLS_SHUTDOWN) {
477+ assert (!(data->flags & CONN_CLOSED));
478+ }
479+
469480 while (!(data->flags & CONN_CLOSED)) {
470481 if (ssl_is_init_fininshed_ (data->ssl )) {
471482 rhs = manapi_do_process (conn, data);
@@ -515,7 +526,7 @@ void manapi::net::worker::TLS::onrecv(const std::shared_ptr<ev::tcp> &watcher, c
515526 }
516527
517528 break ;
518- }
529+ }
519530
520531 // if (err == this->ssl_error_syscall_
521532 // && !this->ssl_is_init_fininshed_(data->ssl))
@@ -531,7 +542,7 @@ void manapi::net::worker::TLS::onrecv(const std::shared_ptr<ev::tcp> &watcher, c
531542 rhs = manapi_do_process (conn, data);
532543 if (rhs == CONN_IO_ERROR)
533544 goto err;
534- }
545+ }
535546 else {
536547 rhs = manapi_do_handshake_ (conn, data);
537548 switch (rhs) {
@@ -563,7 +574,6 @@ void manapi::net::worker::TLS::onrecv(const std::shared_ptr<ev::tcp> &watcher, c
563574 err: {
564575 auto const cdata = conn->as <tls_connection_t >();
565576
566- cdata->flags |= ev::DISCONNECT;
567577 conn->cancellation .cancel ();
568578
569579 this ->close_connection (conn, CLOSE_CONN_SHUTDOWN);
@@ -633,6 +643,9 @@ int manapi::net::worker::TLS::manapi_do_process(const shared_conn &conn, tls_con
633643 this ->shutdown_async_ (conn);
634644 }
635645 else {
646+ if (data->accept_timer )
647+ prepared::timer_clear (std::move (data->accept_timer ));
648+
636649 if (conn->wrk .flags & WRK_INTERFACE_CUSTOM_READ) {
637650 int cursor = 0 ;
638651
@@ -784,7 +797,7 @@ int manapi::net::worker::TLS::ssl_bio_flush_write_(const shared_conn &conn, tls_
784797 ssize_t nfastfast = 0 ;
785798
786799 try {
787- while (!( m->flags & CONN_CLOSED) ) {
800+ while (m->top ) {
788801 if (max_cnt < m->top ->send_size )
789802 break ;
790803
@@ -799,7 +812,8 @@ int manapi::net::worker::TLS::ssl_bio_flush_write_(const shared_conn &conn, tls_
799812
800813 if (rhs > 0 ) {
801814 ssize_t alr = 0 ;
802- if (!m->top ->send_size && rhs > 32 ) {
815+ if (!m->top ->send_size && (rhs > 32 || (m->flags & CONN_TLS_SHUTDOWN))) {
816+ manapi_log_trace_hard (" TLS:write %p flags=%d size=%zu" , m, m->flags , rhs);
803817 alr = m->watcher ->try_write (fastfast, rhs);
804818 if (alr < 0 ) {
805819 if (alr == ev::ERR_AGAIN)
0 commit comments