summaryrefslogtreecommitdiff
path: root/src/ServerConnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ServerConnection.cpp')
-rw-r--r--src/ServerConnection.cpp46
1 files changed, 0 insertions, 46 deletions
diff --git a/src/ServerConnection.cpp b/src/ServerConnection.cpp
deleted file mode 100644
index 64692b6..0000000
--- a/src/ServerConnection.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-#include "ServerConnection.h"
-
-#include <arpa/inet.h>
-#include <csignal>
-#include <netdb.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "ClientConnection.h"
-
-static void error_and_die(const char* message)
-{
- perror(message);
- exit(1);
-}
-
-ServerConnection::ServerConnection(int port)
-{
- sockaddr_in address {};
- int socket_options = 1;
-
- if ((m_socket_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- error_and_die("Failed to create socket");
-
- if (setsockopt(m_socket_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &socket_options, sizeof(socket_options)) != 0)
- error_and_die("setsockopt");
-
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = htonl(INADDR_ANY);
- address.sin_port = htons(port);
-
- if ((bind(m_socket_fd, (sockaddr*)&address, sizeof(address))) < 0)
- error_and_die("bind");
-
- if ((listen(m_socket_fd, 10)) < 0)
- error_and_die("listen");
-}
-
-ClientConnection ServerConnection::accept_client_connection() const
-{
- int client_socket = accept(m_socket_fd, (sockaddr*)nullptr, nullptr);
- return { client_socket };
-}