Implemented server

This commit is contained in:
Nikita Tyukalov, ASUS, Linux
2026-03-24 19:45:17 +03:00
parent c577779635
commit 1cc2ef41d1
3 changed files with 164 additions and 0 deletions

36
server.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef __SERVER_H
#define __SERVER_H
#include <stdbool.h>
#include <stdint.h>
// Open the server.
// Parameters:
// - host - hostname or IP address (domain names are OK)
// - port - port to use
// Returns:
// - -1 on failure
// - file descriptor of the server on success
// Remarks:
// - call only after server_init
// - you must add returned fd to epoll with EPOLLIN events
int server_open(const char* host, int port);
// Close the server.
// Remarks:
// - the socket is automatically removed from epoll
void server_close();
// Notify the server that an event happened on its socket.
// Returns:
// - true on success
// - false on failure
// Remarks:
// - the server accepts the connection and starts managing
// it with connection.h
// - you should stop close the server if this function
// returns false
bool server_event(uint32_t events);
#endif