TCP Node boilerplate; CLI interface
This commit is contained in:
@@ -1,23 +1,18 @@
|
||||
#ifndef TCPSERVER_H
|
||||
#define TCPSERVER_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <tcpd/tcpconnection.h>
|
||||
#include <numgen.h>
|
||||
#include <dynarr.h>
|
||||
|
||||
typedef struct {
|
||||
int sockFd;
|
||||
struct sockaddr_in addr;
|
||||
int opt;
|
||||
int isRunning;
|
||||
void* owner;
|
||||
|
||||
// Called before the client thread runs
|
||||
void (*on_connect)(tcp_connection_t* client);
|
||||
@@ -27,8 +22,9 @@ typedef struct {
|
||||
void (*on_disconnect)(tcp_connection_t* client);
|
||||
|
||||
// max clients
|
||||
size_t clients;
|
||||
size_t maxClients;
|
||||
tcp_connection_t** clientsArrPtr;
|
||||
pthread_mutex_t clientsMutex;
|
||||
|
||||
pthread_t svrThread;
|
||||
} tcp_server_t;
|
||||
@@ -46,8 +42,8 @@ void TcpServer_Destroy(tcp_server_t* ptr);
|
||||
void TcpServer_Init(tcp_server_t* ptr, unsigned short port, const char* addr);
|
||||
void TcpServer_Start(tcp_server_t* ptr, int maxcons);
|
||||
void TcpServer_Stop(tcp_server_t* ptr);
|
||||
void TcpServer_Send(tcp_server_t* ptr, tcp_connection_t* cli, void* data, size_t len);
|
||||
void Generic_SendSocket(int sock, void* data, size_t len);
|
||||
int TcpServer_Send(tcp_server_t* ptr, tcp_connection_t* cli, const void* data, size_t len);
|
||||
void Generic_SendSocket(int sock, const void* data, size_t len);
|
||||
void TcpServer_Disconnect(tcp_server_t* ptr, tcp_connection_t* cli);
|
||||
void TcpServer_KillClient(tcp_server_t* ptr, tcp_connection_t* cli);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user