Browse Source

implement buffer struct, cleanup buffer on page reload

CPP-GTK4
yggverse 2 months ago
parent
commit
8a16e9aa71
  1. 32
      src/app/browser/main/tab/page.cpp
  2. 15
      src/app/browser/main/tab/page.hpp

32
src/app/browser/main/tab/page.cpp

@ -190,6 +190,9 @@ void Page::navigation_reload(
socket__connection socket__connection
); );
// Cleanup previous stream data
buffer.clean();
// Update navigation history? // Update navigation history?
if (ADD_HISTORY) if (ADD_HISTORY)
{ {
@ -349,10 +352,8 @@ void Page::navigation_reload(
// Response // Response
// if (Socket::Connection::is_active(socket__connection)) // @TODO // if (Socket::Connection::is_active(socket__connection)) // @TODO
socket__connection->get_input_stream()->read_all_async( // | read_async @TODO socket__connection->get_input_stream()->read_all_async( // | read_async @TODO
buffer, buffer.data,
sizeof( buffer.capacity(),
buffer
) - 1, // @TODO
[this](const Glib::RefPtr<Gio::AsyncResult>&) [this](const Glib::RefPtr<Gio::AsyncResult>&)
{ {
// Update // Update
@ -372,7 +373,7 @@ void Page::navigation_reload(
// Parse meta // Parse meta
Socket::Client::Gemini::Response::Status status; // @TODO make page global? Socket::Client::Gemini::Response::Status status; // @TODO make page global?
Socket::Client::Gemini::Response::Match::meta( Socket::Client::Gemini::Response::Match::meta(
buffer, buffer.data,
status, status,
mime mime
); );
@ -409,7 +410,7 @@ void Page::navigation_reload(
// Use content driver // Use content driver
pageContent->update( pageContent->update(
page::Content::TEXT_GEMINI, page::Content::TEXT_GEMINI,
buffer, buffer.data,
uri uri
); );
@ -644,6 +645,25 @@ sqlite3_int64 Page::Database::Session::add(
// Socket tools // Socket tools
/*
* Buffer helpers
*/
unsigned long Page::Socket::Buffer::capacity()
{
return sizeof(
data
) - 1;
}
void Page::Socket::Buffer::clean()
{
memset(
data,
0,
DEFAULT_SIZE
);
}
/* /*
* Private helper to build socket client connections * Private helper to build socket client connections
* *

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

@ -84,6 +84,19 @@ namespace app::browser::main::tab
*/ */
struct Socket struct Socket
{ {
struct Buffer
{
// Defaults
static const size_t DEFAULT_SIZE = 0xfffff; // 1Mb
// Stream
char data[DEFAULT_SIZE];
// Tools
unsigned long capacity();
void clean();
};
class Client class Client
{ {
private: private:
@ -185,7 +198,7 @@ namespace app::browser::main::tab
sqlite3 * database; sqlite3 * database;
// Socket // Socket
char buffer[0xfffff]; // 1Mb Socket::Buffer buffer;
// Shared socket connectors (for async operations) // Shared socket connectors (for async operations)
Glib::RefPtr<Gio::SocketClient> socket__client; Glib::RefPtr<Gio::SocketClient> socket__client;

Loading…
Cancel
Save