beginning drafting of tcp server
This commit is contained in:
25
inc/tcp_server.hpp
Normal file
25
inc/tcp_server.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <pthread.h>
|
||||
#include "util.hpp"
|
||||
|
||||
typedef void (*data_received_cb_t)(SOCKET client, array<char> data);
|
||||
|
||||
struct tcpserver {
|
||||
SOCKET sock;
|
||||
array<SOCKET> client_socks;
|
||||
int max_connections;
|
||||
addrinfo *addr;
|
||||
array<data_received_cb_t> cbs;
|
||||
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t connection_ended;
|
||||
pthread_cond_t stop_requested;
|
||||
};
|
||||
|
||||
bool create_server(tcpserver *server_out, const char* hostname, int port);
|
||||
void start_server(tcpserver &s);
|
||||
void stop_server(tcpserver &s);
|
||||
void send_data(tcpserver &s, SOCKET client, array<char> data);
|
||||
void register_recv_cb(tcpserver &s, data_received_cb_t cb);
|
||||
Reference in New Issue
Block a user