@@ -136,11 +136,14 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
136136 if (connection->flags & (ev::DISCONNECT))
137137 return -1 ;
138138
139+ this ->ssl_bio_flush_write_ (conn, connection, maxcnt, false );
140+
139141 char buffer[32768 ];
140142 int cursor = 0 ;
141143 size_t lastcur = 0 ;
142144 ssize_t total = 0 ;
143145
146+
144147 while (nbuff) {
145148 if (connection->top ->send_size > maxcnt)
146149 break ;
@@ -175,37 +178,25 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
175178 rhs = this ->ssl_write_ (connection->ssl , buffer + current,
176179 static_cast <int >(cursor - current));
177180
178- if (rhs > 0 ) {
179- current += rhs;
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+ }
180187
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- }
188+ return CONN_IO_ERROR;
189+ }
187190
188- return CONN_IO_ERROR;
189- }
191+ if (rhs > 0 ) {
192+ current += rhs;
190193 }
191194 else {
192195 int err = this ->ssl_get_error_ (connection->ssl , rhs);
193196
194197 if (err) {
195198 if (err == this ->ssl_error_want_read_
196199 || err == this ->ssl_error_want_write_ ) {
197- auto const erhs = this ->ssl_bio_flush_write_ (conn, connection, maxcnt, false );
198-
199- if (erhs) {
200- if (erhs == CONN_IO_WANT_WRITE) {
201- if (this ->flush_write_ (conn, true ))
202- return CONN_IO_ERROR;
203- return total + current;
204- }
205-
206- return CONN_IO_ERROR;
207- }
208-
209200 if (this ->flush_write_ (conn, true ))
210201 return CONN_IO_ERROR;
211202
@@ -237,17 +228,6 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
237228
238229
239230 bool const cfinish = finish && total == size;
240- auto const err = this ->ssl_bio_flush_write_ (conn, connection, maxcnt, false );
241-
242- if (err) {
243- if (err == CONN_IO_WANT_WRITE) {
244- if (this ->flush_write_ (conn, true ))
245- return CONN_IO_ERROR;
246- return total;
247- }
248-
249- return CONN_IO_ERROR;
250- }
251231
252232 if (this ->flush_write_ (conn, cfinish))
253233 return CONN_IO_ERROR;
0 commit comments