From 3c9b964a6bb8539af1862ce127b9c98ad3b1dab2 Mon Sep 17 00:00:00 2001 From: yggverse Date: Mon, 16 Sep 2024 08:23:02 +0300 Subject: [PATCH] update socket connection --- src/app/browser/main/tab/page.cpp | 47 ++++++++++++++++++------------- src/app/browser/main/tab/page.hpp | 5 ++-- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/app/browser/main/tab/page.cpp b/src/app/browser/main/tab/page.cpp index 8936033f..5fdeac4d 100644 --- a/src/app/browser/main/tab/page.cpp +++ b/src/app/browser/main/tab/page.cpp @@ -248,7 +248,7 @@ void Page::navigation_reload( ); } - // Reset page data + // Reset page meta data mime = MIME::UNDEFINED; title = _("Update"); @@ -272,23 +272,26 @@ void Page::navigation_reload( if (g_uri_get_scheme(uri) == Glib::ustring("gemini")) { // Create new socket connection - GioSocketClient = Gio::SocketClient::create(); + socket__client = Gio::SocketClient::create(); - GioSocketClient->set_tls( + socket__client->set_tls( true ); - GioSocketClient->set_tls_validation_flags( + socket__client->set_tls_validation_flags( Gio::TlsCertificateFlags::NO_FLAGS ); - GioSocketClient->set_timeout( + socket__client->set_timeout( 15 // @TODO ); - GioSocketClient->connect_to_uri_async( - pageNavigation->get_request_text(), 1965, - [this](const Glib::RefPtr & result) + socket__client->connect_to_uri_async( + g_uri_to_string( + uri + ), + 1965, // default port @TODO + [this](const Glib::RefPtr & RESULT) { // Update title = _("Connect"); @@ -306,8 +309,8 @@ void Page::navigation_reload( try { - GioSocketConnection = GioSocketClient->connect_to_uri_finish( - result + socket__connection = socket__client->connect_to_uri_finish( + RESULT ); } @@ -324,14 +327,20 @@ void Page::navigation_reload( } // Connection established, begin request - if (GioSocketConnection != nullptr) + if (socket__connection != nullptr) { - const Glib::ustring request = pageNavigation->get_request_text() + "\r\n"; + // Build gemini protocol request + const Glib::ustring SOCKET__REQUEST = Glib::ustring::sprintf( + "%s\r\n", + g_uri_to_string( + uri + ) + ); - GioSocketConnection->get_output_stream()->write_async( - request.data(), - request.size(), - [this](const Glib::RefPtr & result) + socket__connection->get_output_stream()->write_async( + SOCKET__REQUEST.data(), + SOCKET__REQUEST.size(), + [this](const Glib::RefPtr&) { // Update title = _("Request"); @@ -348,10 +357,10 @@ void Page::navigation_reload( action__update->activate(); // Response - GioSocketConnection->get_input_stream()->read_all_async( // | read_async @TODO + socket__connection->get_input_stream()->read_all_async( // | read_async @TODO buffer, sizeof(buffer) - 1, - [this](const Glib::RefPtr & result) + [this](const Glib::RefPtr&) { // Update title = _("Reading"); @@ -434,7 +443,7 @@ void Page::navigation_reload( action__update->activate(); } - GioSocketConnection->close(); + socket__connection->close(); } ); } diff --git a/src/app/browser/main/tab/page.hpp b/src/app/browser/main/tab/page.hpp index 9ae19f22..6eb733e2 100644 --- a/src/app/browser/main/tab/page.hpp +++ b/src/app/browser/main/tab/page.hpp @@ -100,8 +100,9 @@ namespace app::browser::main::tab // Socket char buffer[0xfffff]; // 1Mb - Glib::RefPtr GioSocketClient; - Glib::RefPtr GioSocketConnection; + // Shared socket connectors (for async operations) + Glib::RefPtr socket__client; + Glib::RefPtr socket__connection; // Components page::Content * pageContent;