@@ -95,9 +95,8 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
95
95
ssize_t res = 0 ;
96
96
97
97
while (res != buff[i].len ) {
98
- if (connection->top ->send_size >= maxcnt) {
99
- return res;
100
- }
98
+ if (connection->top ->send_size > maxcnt)
99
+ return total;
101
100
102
101
auto rhs = this ->ssl_write_ (connection->ssl , static_cast <const char *> (buff[i].base ) + res,
103
102
static_cast <int >(buff[i].len - res));
@@ -118,17 +117,17 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
118
117
}
119
118
120
119
else if (err == this ->ssl_error_want_read_ ) {
121
- return res ;
120
+ return total ;
122
121
}
123
122
124
123
else if (err == this ->ssl_error_want_write_ ) {
125
124
err = this ->ssl_bio_flush_write_ (conn, connection->wbio ,
126
- & connection->top -> send , &connection-> top -> send_size , maxcnt);
125
+ connection->top . get () , maxcnt);
127
126
128
127
if (err) {
129
128
if (err == CONN_IO_WANT_WRITE) {
130
129
this ->flush_write_ (conn, cfinish);
131
- return res ;
130
+ return total ;
132
131
}
133
132
134
133
return CONN_IO_ERROR;
@@ -143,12 +142,12 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
143
142
}
144
143
145
144
err = this ->ssl_bio_flush_write_ (conn, connection->wbio ,
146
- & connection->top -> send , &connection-> top -> send_size , maxcnt);
145
+ connection->top . get () , maxcnt);
147
146
148
147
if (err) {
149
148
if (err == CONN_IO_WANT_WRITE) {
150
149
this ->flush_write_ (conn, cfinish);
151
- return res ;
150
+ return total ;
152
151
}
153
152
154
153
return CONN_IO_ERROR;
@@ -300,7 +299,7 @@ void manapi::net::worker::TLS::onrecv(std::shared_ptr<ev::tcp> &watcher, const s
300
299
301
300
if (status == this ->ssl_error_want_read_ || status == this ->ssl_error_want_write_ ) {
302
301
/* force write all data */
303
- if (this ->ssl_bio_flush_write_ (conn, data->wbio , & data->top -> send , &data-> top -> send_size , 1e5 )) {
302
+ if (this ->ssl_bio_flush_write_ (conn, data->wbio , data->top . get () , 1e5 )) {
304
303
goto err;
305
304
}
306
305
@@ -380,7 +379,7 @@ void manapi::net::worker::TLS::accept_work_(const shared_conn &conn, int flags,
380
379
381
380
if (status == this ->ssl_error_want_write_ || status == this ->ssl_error_want_read_ ) {
382
381
/* force write all data */
383
- if (this ->ssl_bio_flush_write_ (conn, data->wbio , & data->top -> send , &data-> top -> send_size , 1e5 )) {
382
+ if (this ->ssl_bio_flush_write_ (conn, data->wbio , data->top . get () , 1e5 )) {
384
383
goto err;
385
384
}
386
385
@@ -421,7 +420,8 @@ void manapi::net::worker::TLS::accept_work_(const shared_conn &conn, int flags,
421
420
422
421
void manapi::net::worker::TLS::flush_write_ (const shared_conn &connection, bool flush) {
423
422
auto const data = connection->as <TLS::connection_interface>();
424
- if (data->top ->send_size == 1 && data->top ->send .last_deque ) {
423
+ if (flush && data->top ->send_size == 1 ) {
424
+ assert (data->top ->send .last_deque );
425
425
/* in the stack */
426
426
auto &buffer = data->top ->send .deque ->buffer ;
427
427
auto copy = static_cast <int >(data->top ->send .deque_cursor - data->top ->send .deque_current );
@@ -433,6 +433,7 @@ void manapi::net::worker::TLS::flush_write_(const shared_conn &connection, bool
433
433
data->top ->send .deque_current = 0 ;
434
434
data->top ->send .deque_cursor = 0 ;
435
435
data->top ->send_size --;
436
+ data->top ->cur_send_size --;
436
437
return ;
437
438
}
438
439
@@ -453,20 +454,21 @@ int manapi::net::worker::TLS::check_read_stack_full_(connection_interface *data)
453
454
return 0 ;
454
455
}
455
456
456
- int manapi::net::worker::TLS::ssl_bio_flush_write_ (const shared_conn &conn, void *wbio, connection_io_part *top, int *cnt , int max_cnt) {
457
+ int manapi::net::worker::TLS::ssl_bio_flush_write_ (const shared_conn &conn, void *wbio, connection_io *m , int max_cnt) {
457
458
int rhs;
458
459
int flags = 0 ;
459
460
buffer_deque *parent = nullptr ;
461
+ auto top = &m->send ;
460
462
461
463
try {
462
464
do {
463
465
if (!top->last_deque || top->last_deque ->buffer .size () == top->deque_cursor ) {
464
466
this ->flush_write_ (conn, false );
465
467
466
- if (cnt && *cnt >= max_cnt)
468
+ if (m-> send_size > max_cnt)
467
469
return CONN_IO_WANT_WRITE;
468
470
469
- auto buffer = this ->bufferpool ().buffer (1 , this ->config_ ->buffer_size );
471
+ auto buffer = this ->bufferpool ().buffer (this ->config_ ->buffer_size );
470
472
471
473
auto obj = std::make_unique<buffer_deque>(std::move (buffer), nullptr );
472
474
if (top->last_deque ) {
@@ -483,8 +485,8 @@ int manapi::net::worker::TLS::ssl_bio_flush_write_(const shared_conn &conn, void
483
485
484
486
top->deque_cursor = 0 ;
485
487
flags |= 1 /* an empty buffer was created */ ;
486
- if (cnt)
487
- (*cnt) ++;
488
+ m-> send_size ++;
489
+ m-> cur_send_size ++;
488
490
}
489
491
else
490
492
flags = 0 ;
@@ -503,7 +505,9 @@ int manapi::net::worker::TLS::ssl_bio_flush_write_(const shared_conn &conn, void
503
505
504
506
if (!rhs && (flags /* an empty buffer was created */ )) {
505
507
/* remove an empty buffer at the end */
506
- connection_io_trim (top, parent, cnt);
508
+ auto const prev = m->send_size ;
509
+ connection_io_trim (top, parent, &m->send_size );
510
+ m->cur_send_size -= prev - m->send_size ;
507
511
}
508
512
}
509
513
while (rhs > 0 );
0 commit comments