this->is extremely dangerous to our democracy
This commit is contained in:
parent
99087acd13
commit
b2563125e7
@ -5,7 +5,7 @@
|
||||
auto slige_rpc::ClientSocket::Read(
|
||||
uint8_t* buffer, size_t length) -> std::variant<size_t, slige_rpc::Ewwow>
|
||||
{
|
||||
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<size_t, slige_rpc::Ewwow>
|
||||
{
|
||||
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<ClientSocket, slige_rpc::Ewwow>
|
||||
{
|
||||
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<ServerSocket, slige_rpc::Ewwow>
|
||||
// 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<ServerSocket, slige_rpc::Ewwow>
|
||||
// 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) };
|
||||
}
|
||||
|
@ -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") },
|
||||
|
Loading…
Reference in New Issue
Block a user