summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-19 02:31:11 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-09-19 21:10:23 +0430
commit436693c0c907b9a15bd6cccc07304e6332bc7b7b (patch)
tree494319887de437c6590d0cdc2c263e6510f8e953 /Userland/Libraries
parentd3ea0818f3dc6f744e6176e9bd1633e3085d6b71 (diff)
downloadserenity-436693c0c907b9a15bd6cccc07304e6332bc7b7b.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGemini/GeminiJob.cpp5
-rw-r--r--Userland/Libraries/LibHTTP/HttpsJob.cpp6
-rw-r--r--Userland/Libraries/LibTLS/TLSv12.h11
-rw-r--r--Userland/Libraries/LibWebSocket/Impl/TLSv12WebSocketConnectionImpl.cpp5
4 files changed, 20 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGemini/GeminiJob.cpp b/Userland/Libraries/LibGemini/GeminiJob.cpp
index 340d470644..64ff2dbee2 100644
--- a/Userland/Libraries/LibGemini/GeminiJob.cpp
+++ b/Userland/Libraries/LibGemini/GeminiJob.cpp
@@ -93,9 +93,10 @@ void GeminiJob::register_on_ready_to_read(Function<void()> callback)
void GeminiJob::register_on_ready_to_write(Function<void()> callback)
{
- m_socket->on_tls_ready_to_write = [callback = move(callback)](auto&) {
+ m_socket->set_on_tls_ready_to_write([callback = move(callback)](auto& tls) {
+ Core::deferred_invoke([&tls] { tls.set_on_tls_ready_to_write(nullptr); });
callback();
- };
+ });
}
bool GeminiJob::can_read_line() const
diff --git a/Userland/Libraries/LibHTTP/HttpsJob.cpp b/Userland/Libraries/LibHTTP/HttpsJob.cpp
index 0f249fc5fb..abaeb662f6 100644
--- a/Userland/Libraries/LibHTTP/HttpsJob.cpp
+++ b/Userland/Libraries/LibHTTP/HttpsJob.cpp
@@ -68,6 +68,7 @@ void HttpsJob::shutdown()
return;
m_socket->on_tls_ready_to_read = nullptr;
m_socket->on_tls_connected = nullptr;
+ m_socket->set_on_tls_ready_to_write(nullptr);
m_socket = nullptr;
}
@@ -97,9 +98,10 @@ void HttpsJob::register_on_ready_to_read(Function<void()> callback)
void HttpsJob::register_on_ready_to_write(Function<void()> callback)
{
- m_socket->on_tls_ready_to_write = [callback = move(callback)](auto&) {
+ m_socket->set_on_tls_ready_to_write([callback = move(callback)](auto& tls) {
+ Core::deferred_invoke([&tls] { tls.set_on_tls_ready_to_write(nullptr); });
callback();
- };
+ });
}
bool HttpsJob::can_read_line() const
diff --git a/Userland/Libraries/LibTLS/TLSv12.h b/Userland/Libraries/LibTLS/TLSv12.h
index e1702c1a1c..1a84f0713e 100644
--- a/Userland/Libraries/LibTLS/TLSv12.h
+++ b/Userland/Libraries/LibTLS/TLSv12.h
@@ -373,8 +373,16 @@ public:
bool can_read() const { return m_context.application_buffer.size() > 0; }
String read_line(size_t max_size);
+ void set_on_tls_ready_to_write(Function<void(TLSv12&)> function)
+ {
+ on_tls_ready_to_write = move(function);
+ if (on_tls_ready_to_write) {
+ if (is_established())
+ on_tls_ready_to_write(*this);
+ }
+ }
+
Function<void(TLSv12&)> on_tls_ready_to_read;
- Function<void(TLSv12&)> on_tls_ready_to_write;
Function<void(AlertDescription)> on_tls_error;
Function<void()> on_tls_connected;
Function<void()> on_tls_finished;
@@ -521,6 +529,7 @@ private:
i32 m_max_wait_time_for_handshake_in_seconds { 10 };
RefPtr<Core::Timer> m_handshake_timeout_timer;
+ Function<void(TLSv12&)> on_tls_ready_to_write;
};
}
diff --git a/Userland/Libraries/LibWebSocket/Impl/TLSv12WebSocketConnectionImpl.cpp b/Userland/Libraries/LibWebSocket/Impl/TLSv12WebSocketConnectionImpl.cpp
index 370f77c4eb..b3313ca9e6 100644
--- a/Userland/Libraries/LibWebSocket/Impl/TLSv12WebSocketConnectionImpl.cpp
+++ b/Userland/Libraries/LibWebSocket/Impl/TLSv12WebSocketConnectionImpl.cpp
@@ -33,9 +33,10 @@ void TLSv12WebSocketConnectionImpl::connect(ConnectionInfo const& connection)
m_socket->on_tls_ready_to_read = [this](auto&) {
on_ready_to_read();
};
- m_socket->on_tls_ready_to_write = [this](auto&) {
+ m_socket->set_on_tls_ready_to_write([this](auto& tls) {
+ tls.set_on_tls_ready_to_write(nullptr);
on_connected();
- };
+ });
m_socket->on_tls_finished = [this] {
on_connection_error();
};