From b2563125e79a609a3eb242439350e4c02d90aceb Mon Sep 17 00:00:00 2001 From: Theis Pieter Hollebeek Date: Wed, 20 Nov 2024 10:31:03 +0100 Subject: [PATCH] this->is extremely dangerous to our democracy --- runtime/rpc_server.cpp | 19 +++++++++++-------- runtime/rpc_server.hpp | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/runtime/rpc_server.cpp b/runtime/rpc_server.cpp index 8264e28..380763e 100644 --- a/runtime/rpc_server.cpp +++ b/runtime/rpc_server.cpp @@ -5,7 +5,7 @@ auto slige_rpc::ClientSocket::Read( uint8_t* buffer, size_t length) -> std::variant { - ssize_t bytes_read = recv(fd, buffer, length, 0); + ssize_t bytes_read = recv(this->fd, buffer, length, 0); if (bytes_read < 0) { return Ewwow { .message = "unable to read" }; } @@ -15,7 +15,7 @@ auto slige_rpc::ClientSocket::Read( auto slige_rpc::ClientSocket::Write( uint8_t* buffer, size_t length) -> std::variant { - ssize_t bytes_written = send(fd, buffer, length, 0); + ssize_t bytes_written = send(this->fd, buffer, length, 0); if (bytes_written < 0) { return Ewwow { .message = "unable to write" }; } @@ -34,7 +34,9 @@ auto slige_rpc::Socket::Connect() // live as long as child socket ('client)? // - immediate answer is no // 2) does it need to? - if (connect(socket_fd, (struct sockaddr*)&address, sizeof(address)) < 0) { + if (connect( + socket_fd, (struct sockaddr*)&this->address, sizeof(this->address)) + < 0) { return { Ewwow { .message = "could not connect, is the server running?" } }; } @@ -44,17 +46,17 @@ auto slige_rpc::Socket::Connect() auto slige_rpc::ServerSocket::Accept() -> std::variant { - unsigned int address_size = sizeof(address); + unsigned int address_size = sizeof(this->address); // TODO: // 1) does address (presumably 'server) // live as long as child socket ('socket)? // - immediate answer is no // 2) does it need to? - int client = accept(fd, (struct sockaddr*)&address, &address_size); + int client + = accept(this->fd, (struct sockaddr*)&this->address, &address_size); if (client < 0) { return Ewwow { .message = "could not accept" }; } - return client; return { ClientSocket(client) }; } @@ -69,7 +71,8 @@ auto slige_rpc::Socket::Bind() -> std::variant // live as long as child socket ('server)? // - immediate answer is no // 2) does it need to? - if (bind(socket_fd, (struct sockaddr*)&address, sizeof(address)) < 0) { + if (bind(socket_fd, (struct sockaddr*)&this->address, sizeof(this->address)) + < 0) { return { Ewwow { .message = "could not bind" } }; } @@ -80,5 +83,5 @@ auto slige_rpc::Socket::Bind() -> std::variant // 1) does this address get moved, copied or cloned? // it should be represented as a u32, // so copying should be fine - but does it? - return { ServerSocket(socket_fd, address) }; + return { ServerSocket(socket_fd, this->address) }; } diff --git a/runtime/rpc_server.hpp b/runtime/rpc_server.hpp index 14c77c2..9be5447 100644 --- a/runtime/rpc_server.hpp +++ b/runtime/rpc_server.hpp @@ -56,7 +56,7 @@ class Socket { public: Socket(uint16_t port) { - address = { + this->address = { .sin_family = AF_INET, .sin_port = htons(port), .sin_addr = { .s_addr = inet_addr("127.0.0.1") },