Files
dusk/src/network/server/networked/networkedserver.h
2025-04-28 07:49:03 -05:00

56 lines
1.3 KiB
C

/**
* Copyright (c) 2025 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "error/error.h"
#include <netinet/in.h>
#include <arpa/inet.h>
typedef struct {
uint16_t port;
} networkedserverstart_t;
typedef struct {
int socket;
struct sockaddr_in address;
pthread_mutex_t lock;
} networkedserver_t;
typedef struct server_s server_t;
typedef struct serverstart_s serverstart_t;
/**
* Initialize the networked server
*
* This function initializes the networked server by setting up the ENet library
* and creating a server host.
*
* @param server Pointer to the server structure.
* @param start Information about how to start the server.
* @return Returns an error code if the server fails to start.
*/
errorret_t networkedServerStart(server_t *server, const serverstart_t start);
/**
* Stop the networked server
*
* This function stops the networked server by shutting down the ENet library
* and closing the server host.
*
* @param server Pointer to the server structure.
*/
void networkedServerStop(server_t *server);
/**
* Server thread function
*
* This function runs in a separate thread and handles incoming connections,
* messages, and disconnections.
*
* @param arg Pointer to the argument passed to the thread.
*/
void * networkedServerThread(void *arg);