summaryrefslogtreecommitdiff
path: root/include/net/server.hpp
diff options
context:
space:
mode:
authorhovertank3d <[email protected]>2025-11-13 23:07:41 +0100
committerhovertank3d <[email protected]>2025-11-13 23:23:19 +0100
commit9e162e1a3cbf4ea75953bb1f4e2b9440c9456348 (patch)
treef97a1cce84cfbf3ae3f3fceb2211b15543a26efb /include/net/server.hpp
parenta5b377745116de2b269cdfc5b90f08f46d0432d2 (diff)
downloadogurec-9e162e1a3cbf4ea75953bb1f4e2b9440c9456348.tar.gz
ogurec-9e162e1a3cbf4ea75953bb1f4e2b9440c9456348.zip
make clang-format happy
Diffstat (limited to 'include/net/server.hpp')
-rw-r--r--include/net/server.hpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/include/net/server.hpp b/include/net/server.hpp
index 14a5d1d..9a27a25 100644
--- a/include/net/server.hpp
+++ b/include/net/server.hpp
@@ -22,11 +22,10 @@
namespace net {
class server {
- struct sockaddr_in server_address {};
+ struct sockaddr_in server_address { };
int sock_fd;
public:
-
server(std::string hostname, int port)
{
server_address.sin_family = AF_INET;
@@ -34,30 +33,34 @@ public:
server_address.sin_port = htons(port);
}
- ~server() {
+ ~server()
+ {
close(sock_fd);
}
- void bind() {
+ void bind()
+ {
sock_fd = socket(AF_INET, SOCK_STREAM, 0);
- if (sock_fd < 0)
+ if (sock_fd < 0)
throw std::runtime_error(strerror(errno));
-
+
int bindStatus = ::bind(sock_fd, (struct sockaddr*)&server_address, sizeof(server_address));
if (bindStatus < 0)
throw std::runtime_error(strerror(errno));
}
- void listen(int max_connections) {
+ void listen(int max_connections)
+ {
::listen(sock_fd, max_connections);
}
-
- conn accept() {
+
+ conn accept()
+ {
sockaddr_in conn_addr {};
socklen_t conn_addr_size = sizeof(conn_addr);
- int conn_fd = ::accept(sock_fd, (struct sockaddr *)&conn_addr, &conn_addr_size);
- if (conn_fd < 0)
+ int conn_fd = ::accept(sock_fd, (struct sockaddr*)&conn_addr, &conn_addr_size);
+ if (conn_fd < 0)
throw std::runtime_error(strerror(errno));
return conn { conn_fd, conn_addr, conn_addr_size };
}