Browse Source

update socket connection

CPP-GTK4
yggverse 4 days ago
parent
commit
3c9b964a6b
  1. 47
      src/app/browser/main/tab/page.cpp
  2. 5
      src/app/browser/main/tab/page.hpp

47
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; mime = MIME::UNDEFINED;
title = _("Update"); title = _("Update");
@ -272,23 +272,26 @@ void Page::navigation_reload(
if (g_uri_get_scheme(uri) == Glib::ustring("gemini")) if (g_uri_get_scheme(uri) == Glib::ustring("gemini"))
{ {
// Create new socket connection // Create new socket connection
GioSocketClient = Gio::SocketClient::create(); socket__client = Gio::SocketClient::create();
GioSocketClient->set_tls( socket__client->set_tls(
true true
); );
GioSocketClient->set_tls_validation_flags( socket__client->set_tls_validation_flags(
Gio::TlsCertificateFlags::NO_FLAGS Gio::TlsCertificateFlags::NO_FLAGS
); );
GioSocketClient->set_timeout( socket__client->set_timeout(
15 // @TODO 15 // @TODO
); );
GioSocketClient->connect_to_uri_async( socket__client->connect_to_uri_async(
pageNavigation->get_request_text(), 1965, g_uri_to_string(
[this](const Glib::RefPtr<Gio::AsyncResult> & result) uri
),
1965, // default port @TODO
[this](const Glib::RefPtr<Gio::AsyncResult> & RESULT)
{ {
// Update // Update
title = _("Connect"); title = _("Connect");
@ -306,8 +309,8 @@ void Page::navigation_reload(
try try
{ {
GioSocketConnection = GioSocketClient->connect_to_uri_finish( socket__connection = socket__client->connect_to_uri_finish(
result RESULT
); );
} }
@ -324,14 +327,20 @@ void Page::navigation_reload(
} }
// Connection established, begin request // 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( socket__connection->get_output_stream()->write_async(
request.data(), SOCKET__REQUEST.data(),
request.size(), SOCKET__REQUEST.size(),
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult>&)
{ {
// Update // Update
title = _("Request"); title = _("Request");
@ -348,10 +357,10 @@ void Page::navigation_reload(
action__update->activate(); action__update->activate();
// Response // Response
GioSocketConnection->get_input_stream()->read_all_async( // | read_async @TODO socket__connection->get_input_stream()->read_all_async( // | read_async @TODO
buffer, buffer,
sizeof(buffer) - 1, sizeof(buffer) - 1,
[this](const Glib::RefPtr<Gio::AsyncResult> & result) [this](const Glib::RefPtr<Gio::AsyncResult>&)
{ {
// Update // Update
title = _("Reading"); title = _("Reading");
@ -434,7 +443,7 @@ void Page::navigation_reload(
action__update->activate(); action__update->activate();
} }
GioSocketConnection->close(); socket__connection->close();
} }
); );
} }

5
src/app/browser/main/tab/page.hpp

@ -100,8 +100,9 @@ namespace app::browser::main::tab
// Socket // Socket
char buffer[0xfffff]; // 1Mb char buffer[0xfffff]; // 1Mb
Glib::RefPtr<Gio::SocketClient> GioSocketClient; // Shared socket connectors (for async operations)
Glib::RefPtr<Gio::SocketConnection> GioSocketConnection; Glib::RefPtr<Gio::SocketClient> socket__client;
Glib::RefPtr<Gio::SocketConnection> socket__connection;
// Components // Components
page::Content * pageContent; page::Content * pageContent;

Loading…
Cancel
Save