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);
|
||||
@@ -1,13 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
template<class T> struct array {
|
||||
T* data;
|
||||
size_t len;
|
||||
size_t cap;
|
||||
inline T& operator[](int i) { return data[i]; }
|
||||
};
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
template<class T> void append(array<T>& a, T el);
|
||||
template<class T> T pop(array<T>& a);
|
||||
template<class T> void resize(array<T>& a, size_t new_size);
|
||||
bool read_file(array<char>* out, const char* filepath);
|
||||
|
||||
Reference in New Issue
Block a user