Skip to content

Commit f86de61

Browse files
committed
UPD | a lot of smart things
1 parent 03478c3 commit f86de61

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

src/http/base_http.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ manapi::future<void> manapi::net::http::internal::send_file(uq_handle_data_t cda
933933
// goto err;
934934
// }
935935

936-
936+
assert(sv.size() == rhs);
937937
if ((co_await cdata->worker->fwrite (cdata->conn, sv, !readsome)) <= 0)
938938
/* failed to send */
939939
goto err;

src/worker/OpenSSL_TLS.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,22 @@ void * manapi::net::worker::OpenSSL_TLS::ssl_create_context(const size_t &versio
154154
ctx = SSL_CTX_new(method);
155155

156156
if (!ctx)
157-
{
158157
THROW_MANAPIHTTP_EXCEPTION(ERR_INTERNAL, "{}", "cannot create the openssl context for the tcp connection");
159-
}
160158

161-
SSL_CTX_set_options(ctx, SSL_OP_ENABLE_KTLS);
159+
160+
auto ktls = http::config::get_config_param<bool>(
161+
this->config_->ssl, "ktls", true);
162+
auto single_dh_use = http::config::get_config_param<bool>(
163+
this->config_->ssl, "single_dh_use", false);
164+
auto ktls_tx_zerocopy_senfile = http::config::get_config_param<bool>(
165+
this->config_->ssl, "ktls_tx_zerocopy_senfile", true);
166+
167+
if (ktls)
168+
SSL_CTX_set_options(ctx, SSL_OP_ENABLE_KTLS);
169+
if (ktls_tx_zerocopy_senfile)
170+
SSL_CTX_set_options(ctx, SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE);
171+
172+
162173
SSL_CTX_set_max_early_data(ctx, 16384);
163174
SSL_CTX_clear_options(ctx, SSL_OP_NO_COMPRESSION);
164175
SSL_CTX_set_min_proto_version(ctx, 0);
@@ -170,7 +181,9 @@ void * manapi::net::worker::OpenSSL_TLS::ssl_create_context(const size_t &versio
170181
//SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_TICKET);
171182
//SSL_CTX_set_session_id_context(ctx, reinterpret_cast<const unsigned char *>(&this->ssl_session_ctx_id), sizeof(this->ssl_session_ctx_id));
172183

173-
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
184+
if (single_dh_use)
185+
SSL_CTX_set_options(ctx, SSL_OP_SINGLE_DH_USE);
186+
174187
SSL_CTX_set_mode(ctx, SSL_MODE_RELEASE_BUFFERS);
175188

176189
if (cipher_list.empty()) {

src/worker/TCP.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,10 @@ ssize_t manapi::net::worker::TCP::sync_write_ex(const worker::shared_conn &conn,
452452
rhs = connection->watcher->try_write(buff, nbuff);
453453

454454
if (rhs < 0)
455-
rhs = 0;
455+
if (errno == EAGAIN || errno == EWOULDBLOCK)
456+
rhs = 0;
457+
else
458+
return -1;
456459
else
457460
connection->transfered += rhs;
458461
}
@@ -477,7 +480,7 @@ ssize_t manapi::net::worker::TCP::sync_write_ex(const worker::shared_conn &conn,
477480
auto const prev = connection->top->send_size;
478481
auto const result = connection_io_send (&connection->top->send, static_cast<const char *>(buff[i].base), buff[i].len, &this->bufferpool(),
479482
this->config_->buffer_size, &connection->top->send_size, maxcnt);
480-
connection->top->cur_send_size += prev - connection->top->send_size;
483+
connection->top->cur_send_size += connection->top->send_size - prev;
481484

482485
if (result < 0)
483486
return -1;
@@ -601,9 +604,13 @@ int manapi::net::worker::TCP::flush_write_(const worker::shared_conn &connection
601604
}
602605
else {
603606
if (rhs < 0) {
604-
conn->top->send_size -= conn->top->cur_send_size;
605-
conn->top->cur_send_size = 0;
606-
return CONN_IO_ERROR;
607+
if (errno == EAGAIN || errno == EWOULDBLOCK)
608+
rhs = 0;
609+
else {
610+
conn->top->send_size -= conn->top->cur_send_size;
611+
conn->top->cur_send_size = 0;
612+
return CONN_IO_ERROR;
613+
}
607614
}
608615

609616

@@ -642,7 +649,7 @@ int manapi::net::worker::TCP::flush_write_(const worker::shared_conn &connection
642649
conn->ev_callback->operator()(connection, ev::DISCONNECT, nullptr, 0, nullptr);
643650
}
644651
else {
645-
if (conn->status & ev::WRITE)
652+
if (conn->status & ev::WRITE && conn->ev_callback)
646653
conn->ev_callback->operator()(connection, ev::WRITE, nullptr, 0, nullptr);
647654
}
648655

src/worker/TLS.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,13 @@ int manapi::net::worker::TLS::ssl_bio_flush_write_(const shared_conn &conn, TLS:
496496
if (!m->top->send_size) {
497497
alr = m->watcher->try_write(fastfast, rhs);
498498
if (alr < 0) {
499-
/* fatal error */
500-
return CONN_IO_ERROR;
499+
if (errno == EAGAIN || errno == EWOULDBLOCK)
500+
/* fatal error */
501+
return CONN_IO_ERROR;
502+
503+
alr = 0;
501504
}
505+
502506
if (alr == rhs)
503507
continue;
504508
}

0 commit comments

Comments
 (0)