@@ -175,8 +175,19 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
175175 rhs = this ->ssl_write_ (connection->ssl , buffer + current,
176176 static_cast <int >(cursor - current));
177177
178- if (rhs > 0 )
178+ if (rhs > 0 ) {
179179 current += rhs;
180+
181+ if (int erhs = this ->ssl_bio_flush_write_ (conn, connection, maxcnt, false )) {
182+ if (erhs == CONN_IO_WANT_WRITE) {
183+ if (this ->flush_write_ (conn, true ))
184+ return CONN_IO_ERROR;
185+ return total + current;
186+ }
187+
188+ return CONN_IO_ERROR;
189+ }
190+ }
180191 else {
181192 int err = this ->ssl_get_error_ (connection->ssl , rhs);
182193
@@ -253,7 +264,7 @@ ssize_t manapi::net::worker::TLS::sync_write(const shared_conn &conn, ev::buff_t
253264 if (!size)
254265 return size;
255266
256- return this ->sync_write_ex (conn, buff, nbuff, size, finish, static_cast < int >( this ->config_ ->max_buffer_stack ) );
267+ return this ->sync_write_ex (conn, buff, nbuff, size, finish, this ->config_ ->max_buffer_stack );
257268}
258269
259270int manapi::net::worker::TLS::event_flags (const shared_conn & conn, int flags) MANAPIHTTP_NOEXCEPT {
@@ -611,20 +622,27 @@ int manapi::net::worker::TLS::conn_after_write(const worker::shared_conn &conn)
611622 return rhs;
612623 }
613624
614- auto const err = this ->ssl_bio_flush_write_ (conn, conn->as <tls_connection_t >(),
625+ auto const m = conn->as <tls_connection_t >();
626+
627+ auto const err = this ->ssl_bio_flush_write_ (conn, m,
615628 this ->config_ ->max_buffer_stack , false );
616629
617630 if (err) {
618631 if (err == CONN_IO_WANT_WRITE) {
619632 if (this ->flush_write_ (conn, true )) {
620- this ->close_connection (conn, CLOSE_CONN_ERR);
621-
622633 return ERR_UNAVAILABLE;
623634 }
635+
624636 return ERR_OK;
625637 }
626638
627- this ->close_connection (conn, CLOSE_CONN_ERR);
639+ return ERR_UNKNOWN;
640+ }
641+
642+ if (m->flags & CONN_TLS_SHUTDOWN || !ssl_is_init_fininshed_ (m->ssl )) {
643+ if (this ->flush_write_ (conn, true )) {
644+ return ERR_UNAVAILABLE;
645+ }
628646 }
629647
630648 return ERR_OK;
0 commit comments