@@ -212,8 +212,7 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
212
212
if (err) {
213
213
if (err == this ->ssl_error_want_read_
214
214
|| err == this ->ssl_error_want_write_ ) {
215
- err = this ->ssl_bio_flush_write_ (conn, connection->wbio ,
216
- connection->top .get (), maxcnt);
215
+ err = this ->ssl_bio_flush_write_ (conn, connection, maxcnt);
217
216
218
217
if (err) {
219
218
if (err == CONN_IO_WANT_WRITE) {
@@ -244,8 +243,7 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
244
243
245
244
bool const cfinish = finish && total == size;
246
245
247
- auto const err = this ->ssl_bio_flush_write_ (conn, connection->wbio ,
248
- connection->top .get (), maxcnt);
246
+ auto const err = this ->ssl_bio_flush_write_ (conn, connection, maxcnt);
249
247
250
248
if (err) {
251
249
if (err == CONN_IO_WANT_WRITE) {
@@ -403,7 +401,7 @@ void manapi::net::worker::TLS::onrecv(std::shared_ptr<ev::tcp> &watcher, const s
403
401
404
402
if (status == this ->ssl_error_want_read_ || status == this ->ssl_error_want_write_ ) {
405
403
/* force write all data */
406
- if (this ->ssl_bio_flush_write_ (conn, data-> wbio , data-> top . get () , 1e5 )) {
404
+ if (this ->ssl_bio_flush_write_ (conn, data, 1e5 )) {
407
405
goto err;
408
406
}
409
407
@@ -467,111 +465,124 @@ int manapi::net::worker::TLS::check_read_stack_full_(connection_interface *data)
467
465
return 0 ;
468
466
}
469
467
470
- int manapi::net::worker::TLS::ssl_bio_flush_write_ (const shared_conn &conn, void *wbio, connection_io *m, int max_cnt) {
468
+ int manapi::net::worker::TLS::ssl_bio_flush_write_ (const shared_conn &conn, TLS::connection_interface *m, int max_cnt) {
471
469
int rhs;
472
470
int flags = 0 ;
473
471
buffer_deque *parent = nullptr ;
474
- auto top = &m->send ;
475
- //
476
- // char fastfast[16356];
477
- // ssize_t nfastfast = 0;
478
- //
479
- // try {
480
- // while (true) {
481
- // if (max_cnt < m->send_size)
482
- // break;
483
- //
484
- // if (max_cnt < 10000)
485
- // nfastfast = std::min<ssize_t>((max_cnt - m->send_size + 1) * this->config_->buffer_size,
486
- // (sizeof (fastfast)));
487
- // else
488
- // nfastfast = sizeof (fastfast);
489
- //
490
- // rhs = this->ssl_bio_read_(wbio, fastfast,
491
- // static_cast<int>(nfastfast));
492
- //
493
- // if (rhs > 0) {
494
- // auto const prev = m->send_size;
495
- // TLS::connection_io_send(top, fastfast, rhs, &this->bufferpool(), this->config_->buffer_size, &m->send_size, 1e5);
496
- // m->cur_send_size += m->send_size - prev;
497
- //
498
- // this->flush_write_(conn, false);
499
- // }
500
- // else {
501
- // if (!this->ssl_bio_should_retry_(wbio)) {
502
- // return CONN_IO_ERROR;
503
- // }
504
- // break;
505
- // }
506
- // }
507
- // return CONN_IO_OK;
508
- // }
509
- // catch (std::exception const &e) {
510
- // manapi::async::current()->logger()->error(manapi::logger::default_service,
511
- // manapi::ERR_INTERNAL, "TLS::ssl_bio_flush_write_(...): {}", e.what());
512
- // }
472
+ auto top = &m->top ->send ;
473
+
474
+ char fastfast[65536 ];
475
+ ssize_t nfastfast = 0 ;
513
476
514
477
try {
515
- do {
516
- if (!top->last_deque || top->last_deque ->buffer .size () == top->deque_cursor ) {
517
- if (this ->flush_write_ (conn, false ))
518
- return CONN_IO_ERROR;
478
+ while (true ) {
479
+ if (max_cnt < m->top ->send_size )
480
+ break ;
519
481
520
- if (m->send_size > max_cnt)
521
- return CONN_IO_WANT_WRITE;
482
+ if (max_cnt < 10000 )
483
+ nfastfast = std::min<ssize_t >((max_cnt - m->top ->send_size + 1 ) * this ->config_ ->buffer_size ,
484
+ (sizeof (fastfast)));
485
+ else
486
+ nfastfast = sizeof (fastfast);
522
487
523
- auto buffer = this ->bufferpool ().buffer (this ->config_ ->buffer_size );
488
+ rhs = this ->ssl_bio_read_ (m->wbio , fastfast,
489
+ static_cast <int >(nfastfast));
524
490
525
- auto obj = std::make_unique<buffer_deque>(std::move (buffer), nullptr );
526
- if (top->last_deque ) {
527
- parent = top->last_deque ;
528
- top->last_deque ->next = std::move (obj);
529
- top->last_deque = top->last_deque ->next .get ();
530
- }
531
- else {
532
- parent = nullptr ;
533
- top->deque = std::move (obj);
534
- top->last_deque = top->deque .get ();
535
- top->deque_current = 0 ;
491
+ if (rhs > 0 ) {
492
+ ssize_t alr = 0 ;
493
+ if (!m->top ->send_size ) {
494
+ alr = m->watcher ->try_write (fastfast, rhs);
495
+ if (alr < 0 ) {
496
+ /* fatal error */
497
+ return CONN_IO_ERROR;
498
+ }
499
+ if (alr == rhs)
500
+ continue ;
536
501
}
537
502
538
- top->deque_cursor = 0 ;
539
- flags |= 1 /* an empty buffer was created */ ;
540
- m->send_size ++;
541
- m->cur_send_size ++;
542
- }
543
- else if (flags)
544
- flags = 0 ;
503
+ auto const prev = m->top ->send_size ;
504
+ TLS::connection_io_send (top, fastfast + alr, rhs - alr, &this ->bufferpool (),
505
+ this ->config_ ->buffer_size , &m->top ->send_size , 1e5 );
506
+ m->top ->cur_send_size += m->top ->send_size - prev;
545
507
546
- rhs = this ->ssl_bio_read_ (wbio, top->last_deque ->buffer .data () + top->deque_cursor ,
547
- static_cast <int >(top->last_deque ->buffer .size () - top->deque_cursor ));
508
+ this ->flush_write_ (conn, false );
548
509
549
- if (rhs > 0 ) {
550
- top->deque_cursor += rhs;
551
510
}
552
511
else {
553
- if (!this ->ssl_bio_should_retry_ (wbio)) {
512
+ if (!this ->ssl_bio_should_retry_ (m-> wbio )) {
554
513
return CONN_IO_ERROR;
555
514
}
556
- rhs = 0 ;
557
- }
558
-
559
- if (!rhs && (flags /* an empty buffer was created */ )) {
560
- /* remove an empty buffer at the end */
561
- auto const prev = m->send_size ;
562
- connection_io_trim (top, parent, &m->send_size );
563
- m->cur_send_size -= prev - m->send_size ;
515
+ break ;
564
516
}
565
517
}
566
- while (rhs > 0 );
567
-
568
518
return CONN_IO_OK;
569
519
}
570
520
catch (std::exception const &e) {
571
521
manapi::async::current ()->logger ()->error (manapi::logger::default_service,
572
522
manapi::ERR_INTERNAL, " TLS::ssl_bio_flush_write_(...): {}" , e.what ());
573
523
}
574
524
525
+ // try {
526
+ // do {
527
+ // if (!top->last_deque || top->last_deque->buffer.size() == top->deque_cursor) {
528
+ // if (this->flush_write_(conn, false))
529
+ // return CONN_IO_ERROR;
530
+ //
531
+ // if (m->send_size > max_cnt)
532
+ // return CONN_IO_WANT_WRITE;
533
+ //
534
+ // auto buffer = this->bufferpool().buffer(this->config_->buffer_size);
535
+ //
536
+ // auto obj = std::make_unique<buffer_deque>(std::move(buffer), nullptr);
537
+ // if (top->last_deque) {
538
+ // parent = top->last_deque;
539
+ // top->last_deque->next = std::move(obj);
540
+ // top->last_deque = top->last_deque->next.get();
541
+ // }
542
+ // else {
543
+ // parent = nullptr;
544
+ // top->deque = std::move(obj);
545
+ // top->last_deque = top->deque.get();
546
+ // top->deque_current = 0;
547
+ // }
548
+ //
549
+ // top->deque_cursor = 0;
550
+ // flags |= 1 /* an empty buffer was created */;
551
+ // m->send_size++;
552
+ // m->cur_send_size++;
553
+ // }
554
+ // else if (flags)
555
+ // flags = 0;
556
+ //
557
+ // rhs = this->ssl_bio_read_(wbio, top->last_deque->buffer.data() + top->deque_cursor,
558
+ // static_cast<int>(top->last_deque->buffer.size() - top->deque_cursor));
559
+ //
560
+ // if (rhs > 0) {
561
+ // top->deque_cursor += rhs;
562
+ // }
563
+ // else {
564
+ // if (!this->ssl_bio_should_retry_(wbio)) {
565
+ // return CONN_IO_ERROR;
566
+ // }
567
+ // rhs = 0;
568
+ // }
569
+ //
570
+ // if (!rhs && (flags /* an empty buffer was created */ )) {
571
+ // /* remove an empty buffer at the end */
572
+ // auto const prev = m->send_size;
573
+ // connection_io_trim(top, parent, &m->send_size);
574
+ // m->cur_send_size -= prev - m->send_size;
575
+ // }
576
+ // }
577
+ // while (rhs > 0);
578
+ //
579
+ // return CONN_IO_OK;
580
+ // }
581
+ // catch (std::exception const &e) {
582
+ // manapi::async::current()->logger()->error(manapi::logger::default_service,
583
+ // manapi::ERR_INTERNAL, "TLS::ssl_bio_flush_write_(...): {}", e.what());
584
+ // }
585
+
575
586
return CONN_IO_ERROR;
576
587
}
577
588
0 commit comments