mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:17:45 +00:00
LibTLS: Use a setter for on_tls_ready_to_write with some more smarts
The callback should be called as soon as the connection is established, and if we actually set the callback when it already is, we expect it to be called immediately.
This commit is contained in:
parent
d3ea0818f3
commit
436693c0c9
6 changed files with 28 additions and 13 deletions
|
@ -152,12 +152,12 @@ static void tls(const char* message, size_t len)
|
|||
if (buffer.has_value())
|
||||
out("{}", StringView { buffer->data(), buffer->size() });
|
||||
};
|
||||
tls->on_tls_ready_to_write = [&](auto&) {
|
||||
tls->set_on_tls_ready_to_write([&](auto&) {
|
||||
if (write.size()) {
|
||||
tls->write(write);
|
||||
write.clear();
|
||||
}
|
||||
};
|
||||
});
|
||||
tls->on_tls_error = [&](auto) {
|
||||
g_loop.quit(1);
|
||||
};
|
||||
|
@ -2013,10 +2013,11 @@ static void tls_test_client_hello()
|
|||
tls->set_root_certificates(s_root_ca_certificates);
|
||||
bool sent_request = false;
|
||||
ByteBuffer contents;
|
||||
tls->on_tls_ready_to_write = [&](TLS::TLSv12& tls) {
|
||||
tls->set_on_tls_ready_to_write([&](TLS::TLSv12& tls) {
|
||||
if (sent_request)
|
||||
return;
|
||||
sent_request = true;
|
||||
Core::deferred_invoke([&tls] { tls.set_on_tls_ready_to_write(nullptr); });
|
||||
if (!tls.write("GET / HTTP/1.1\r\nHost: "_b)) {
|
||||
FAIL(write(0) failed);
|
||||
loop.quit(0);
|
||||
|
@ -2030,7 +2031,7 @@ static void tls_test_client_hello()
|
|||
FAIL(write(2) failed);
|
||||
loop.quit(0);
|
||||
}
|
||||
};
|
||||
});
|
||||
tls->on_tls_ready_to_read = [&](TLS::TLSv12& tls) {
|
||||
auto data = tls.read();
|
||||
if (!data.has_value()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue