Moved network code under /network

This commit is contained in:
2025-04-23 08:07:17 -05:00
parent 44ebe1e1da
commit 05523c1cf9
32 changed files with 30 additions and 22 deletions

View File

@ -0,0 +1,57 @@
/**
* 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;
pthread_cond_t cond;
} 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);