Skip to content

Commit 95873bf

Browse files
committed
UPD | tls max is 1.8gbs using 4K slices
1 parent 302369d commit 95873bf

File tree

3 files changed

+101
-87
lines changed

3 files changed

+101
-87
lines changed

include/worker/TLS.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace manapi::net::worker {
8484
private:
8585
int check_read_stack_full_ (connection_interface *data);
8686

87-
int ssl_bio_flush_write_ (const shared_conn &conn, void *wbio, connection_io *m, int max_cnt);
87+
int ssl_bio_flush_write_ (const shared_conn &conn, TLS::connection_interface *m, int max_cnt);
8888

8989
int ssl_bio_flush_read_ (const shared_conn &conn, void *rbio, connection_io_part *top, int *cnt, int max_cnt);
9090

src/worker/TCP.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,8 +597,11 @@ int manapi::net::worker::TCP::flush_write_(const worker::shared_conn &connection
597597
conn->top->cur_send_size = 0;
598598
}
599599
else {
600-
if (rhs < 0)
600+
if (rhs < 0) {
601+
conn->top->send_size -= conn->top->cur_send_size;
602+
conn->top->cur_send_size = 0;
601603
return CONN_IO_ERROR;
604+
}
602605

603606

604607
uint32_t cursor = 0;

src/worker/TLS.cpp

Lines changed: 96 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
212212
if (err) {
213213
if (err == this->ssl_error_want_read_
214214
|| 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);
217216

218217
if (err) {
219218
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
244243

245244
bool const cfinish = finish && total == size;
246245

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);
249247

250248
if (err) {
251249
if (err == CONN_IO_WANT_WRITE) {
@@ -403,7 +401,7 @@ void manapi::net::worker::TLS::onrecv(std::shared_ptr<ev::tcp> &watcher, const s
403401

404402
if (status == this->ssl_error_want_read_ || status == this->ssl_error_want_write_) {
405403
/* 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)) {
407405
goto err;
408406
}
409407

@@ -467,111 +465,124 @@ int manapi::net::worker::TLS::check_read_stack_full_(connection_interface *data)
467465
return 0;
468466
}
469467

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) {
471469
int rhs;
472470
int flags = 0;
473471
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;
513476

514477
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;
519481

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);
522487

523-
auto buffer = this->bufferpool().buffer(this->config_->buffer_size);
488+
rhs = this->ssl_bio_read_(m->wbio, fastfast,
489+
static_cast<int>(nfastfast));
524490

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;
536501
}
537502

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;
545507

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);
548509

549-
if (rhs > 0) {
550-
top->deque_cursor += rhs;
551510
}
552511
else {
553-
if (!this->ssl_bio_should_retry_(wbio)) {
512+
if (!this->ssl_bio_should_retry_(m->wbio)) {
554513
return CONN_IO_ERROR;
555514
}
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;
564516
}
565517
}
566-
while (rhs > 0);
567-
568518
return CONN_IO_OK;
569519
}
570520
catch (std::exception const &e) {
571521
manapi::async::current()->logger()->error(manapi::logger::default_service,
572522
manapi::ERR_INTERNAL, "TLS::ssl_bio_flush_write_(...): {}", e.what());
573523
}
574524

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+
575586
return CONN_IO_ERROR;
576587
}
577588

0 commit comments

Comments
 (0)