Browse Source

implement buffer struct, cleanup buffer on page reload

CPP-GTK4
yggverse 3 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( @@ -190,6 +190,9 @@ void Page::navigation_reload(
socket__connection
);
// Cleanup previous stream data
buffer.clean();
// Update navigation history?
if (ADD_HISTORY)
{
@ -349,10 +352,8 @@ void Page::navigation_reload( @@ -349,10 +352,8 @@ void Page::navigation_reload(
// Response
// if (Socket::Connection::is_active(socket__connection)) // @TODO
socket__connection->get_input_stream()->read_all_async( // | read_async @TODO
buffer,
sizeof(
buffer
) - 1, // @TODO
buffer.data,
buffer.capacity(),
[this](const Glib::RefPtr<Gio::AsyncResult>&)
{
// Update
@ -372,7 +373,7 @@ void Page::navigation_reload( @@ -372,7 +373,7 @@ void Page::navigation_reload(
// Parse meta
Socket::Client::Gemini::Response::Status status; // @TODO make page global?
Socket::Client::Gemini::Response::Match::meta(
buffer,
buffer.data,
status,
mime
);
@ -409,7 +410,7 @@ void Page::navigation_reload( @@ -409,7 +410,7 @@ void Page::navigation_reload(
// Use content driver
pageContent->update(
page::Content::TEXT_GEMINI,
buffer,
buffer.data,
uri
);
@ -644,6 +645,25 @@ sqlite3_int64 Page::Database::Session::add( @@ -644,6 +645,25 @@ sqlite3_int64 Page::Database::Session::add(
// 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
*

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

@ -84,6 +84,19 @@ namespace app::browser::main::tab @@ -84,6 +84,19 @@ namespace app::browser::main::tab
*/
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
{
private:
@ -185,7 +198,7 @@ namespace app::browser::main::tab @@ -185,7 +198,7 @@ namespace app::browser::main::tab
sqlite3 * database;
// Socket
char buffer[0xfffff]; // 1Mb
Socket::Buffer buffer;
// Shared socket connectors (for async operations)
Glib::RefPtr<Gio::SocketClient> socket__client;

Loading…
Cancel
Save