Browse Source

Start of cleanup

master
dirkson 3 years ago
parent
commit
314fa9c07e
  1. 20
      .lvimrc
  2. 45
      include/parasol.h
  3. 289
      src/parasol.c

20
.lvimrc

@ -0,0 +1,20 @@
"Stuff you're more likely to edit goes near the top
let s:projstd = '-std=gnu89 -Wall'
let s:projinc = '-Iinclude -Isrc -Imeson/debug -Isrc/examples '
let s:projopt = ''
let g:ale_linters = {'c': ['clang', 'clangcheck']}
"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck']}
"let g:ale_linters = {'c': ['clang', 'clangtidy', 'clangd', 'cppcheck','cquery', 'flawfinder', 'gcc']}
let s:projstrn = s:projstd.' '.s:projopt.' '.s:projinc
let g:ale_c_clang_options = s:projstrn
let g:ale_c_clangd_options = s:projstrn
let g:ale_c_clangformat_options = s:projstrn
let g:ale_c_clangcheck_options = s:projstrn
let g:ale_c_cppcheck_options = s:projstrn
let g:ale_c_gcc_options = s:projstrn
"Use build_dir instead
"let g:ale_c_clangtidy_options = projstrn
let g:ale_c_build_dir = 'meson/debug'

45
include/parasol.h

@ -1,28 +1,24 @@
#include <uv.h>
char InitUv();
uv_loop_t *UvLoop;
//Global variables
char DoIpv6;
//Watchers
uv_udp_t *UvUdp4;
uv_udp_t *UvUdp6;
//uv_udp_send_t UvUdpSend4;
//uv_udp_send_t UvUdpSend6;
uv_tcp_t *UvTcp4;
uv_tcp_t *UvTcp6;
typedef enum parasol_return
{
PARASOL_FAILURE,
PARASOL_SUCCESS,
PARASOL_FAILURE_INIT,
PARASOL_FAILURE_ALLOC,
PARASOL_FAILURE_LISTEN,
uv_tcp_t *UvTcp4File;
uv_tcp_t *UvTcp6File;
} parasol_return;
uv_stream_t* TcpConnectStream;
uv_stream_t* TcpFileConnectStream;
const char* parasol_return_str[] =
{
"Failure",
"Success",
"Initialization failure",
"Allocation failure",
"Listen failure",
};
typedef struct
@ -70,11 +66,12 @@ typedef struct
//Definitions
char InitUvTcp(char[17], char[40], unsigned short int, unsigned short int);
char InitUvUdp(char[17], char[40], unsigned short int);
char InitUvTcpClient(char [40], unsigned short int);
parasol_return parasol_init();
parasol_return parasol_init_tcp(char[17], char[40], unsigned short int, unsigned short int);
parasol_return parasol_init_udp(char[17], char[40], unsigned short int);
char parason_init_tcp_client(char [40], unsigned short int);
void TeardownUv();
void parasol_cleanup();
void UdpSingleSend(struct sockaddr*, uv_buf_t);
void UdpSingleSendIP(char[40], unsigned short int, unsigned char*, short int);

289
src/parasol.c

@ -2,7 +2,7 @@
#include <stdlib.h>
#include "parasol.h"
static uv_buf_t AllocateUDP(uv_handle_t*, size_t);
static uv_buf_t parasol_allocate_udp(uv_handle_t*, size_t);
void ResetUserTcpConnection(UserTcpConnection*, unsigned int);
void ResetUserTcpConnectionFileData(UserTcpFileConnection*);
void UvTcpConnect(uv_connect_t *, int);
@ -19,114 +19,134 @@ void NewTcpFileConnection(uv_stream_t*, int);
void ReceiveTcpData(uv_stream_t*, ssize_t, uv_buf_t);
void ReceiveTcpFile(uv_stream_t*, ssize_t, uv_buf_t);
typedef struct parasol_data_t
{
int
do_ipv6 : 1
;
//Receive "packet" callbacks
//UV data
uv_loop_t *loop;
uv_udp_t *udp4;
uv_udp_t *udp6;
uv_tcp_t *tcp4;
uv_tcp_t *tcp6;
uv_tcp_t *file4;
uv_tcp_t *file6;
uv_stream_t* tcp_connect_stream;
uv_stream_t* file_connect_stream;
} parasol_data_t;
parasol_data_t parasol_data;
char InitUv()
//Creates a libuv quick tcp channel, libuv file tcp channel, and a udp channel
parasol_return parasol_init() //InitUV()
{
DoIpv6 = 0;
parasol_data.do_ipv6 = 0;
//Main loop
UvLoop = NULL;
//UvLoop = (uv_loop_t *)calloc(sizeof(uv_loop_t), 1);
UvLoop = uv_loop_new();
if (UvLoop == NULL)
return Error("Cannot init uv loop.");
parasol_data.loop = NULL;
//parasol_data.loop = (uv_loop_t *)calloc(sizeof(uv_loop_t), 1);
parasol_data.loop = uv_loop_new();
if (parasol_data.loop == NULL)
return PARASOL_FAILURE_INIT;
//Watchers
//Udp
if (DoIpv6)
if (parasol_data.do_ipv6)
{
//udp
UvUdp6 = NULL;
UvUdp6 = (uv_udp_t *)calloc(sizeof(uv_udp_t), 1);
if (UvUdp6 == NULL)
return Error("Cannot allocate uv UDP 6");
if (uv_udp_init(UvLoop, UvUdp6) != 0)
return Error("Cannot init uv UDP 6");
parasol_data.udp6 = NULL;
parasol_data.udp6 = (uv_udp_t *)calloc(sizeof(uv_udp_t), 1);
if (parasol_data.udp6 == NULL)
return PARASOL_FAILURE_ALLOC;
if (uv_udp_init(parasol_data.loop, parasol_data.udp6) != 0)
return PARASOL_FAILURE_INIT;
//tcp
UvTcp6 = NULL;
UvTcp6 = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (UvTcp6 == NULL)
return Error("Cannot allocate uv TCP 6");
if (uv_tcp_init(UvLoop, UvTcp6) != 0)
return Error("Cannot init uv TCP 6");
parasol_data.tcp6 = NULL;
parasol_data.tcp6 = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (parasol_data.tcp6 == NULL)
return PARASOL_FAILURE_ALLOC;
if (uv_tcp_init(parasol_data.loop, parasol_data.tcp6) != 0)
return PARASOL_FAILURE_INIT;
//tcpfile
UvTcp6File = NULL;
UvTcp6File = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (UvTcp6File == NULL)
return Error("Cannot allocate uv TCP 6 file");
if (uv_tcp_init(UvLoop, UvTcp6File) != 0)
return Error("Cannot init uv TCP 6 file");
parasol_data.file6 = NULL;
parasol_data.file6 = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (parasol_data.file6 == NULL)
return PARASOL_FAILURE_ALLOC;
if (uv_tcp_init(parasol_data.loop, parasol_data.file6) != 0)
return PARASOL_FAILURE_INIT;
//0 ENABLES Nagle's algorithm, and is default.
//uv_tcp_nodelay(UvTcp6, 0);
//uv_tcp_nodelay(parasol_data.tcp6, 0);
//Keepalive is DISABLED by default.
uv_tcp_keepalive(UvTcp6, 1, 0);
uv_tcp_keepalive(UvTcp6File, 1, 0);
uv_tcp_keepalive(parasol_data.tcp6, 1, 0);
uv_tcp_keepalive(parasol_data.file6, 1, 0);
}
//ipv4
UvUdp4 = NULL;
UvUdp4 = (uv_udp_t *)calloc(sizeof(uv_udp_t), 1);
if (UvUdp4 == NULL)
return Error("Cannot allocate uv UDP 4");
if (uv_udp_init(UvLoop, UvUdp4) != 0)
{
return Error("Unknown Error");
}
parasol_data.udp4 = NULL;
parasol_data.udp4 = (uv_udp_t *)calloc(sizeof(uv_udp_t), 1);
if (parasol_data.udp4 == NULL)
return PARASOL_FAILURE_ALLOC;
if (uv_udp_init(parasol_data.loop, parasol_data.udp4) != 0)
return PARASOL_FAILURE_INIT;
//tcp
UvTcp4 = NULL;
UvTcp4 = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (UvTcp4 == NULL)
return Error("Cannot allocate uv TCP");
if (uv_tcp_init(UvLoop, UvTcp4) != 0)
return Error("Cannot init uv TCP");
parasol_data.tcp4 = NULL;
parasol_data.tcp4 = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (parasol_data.tcp4 == NULL)
return PARASOL_FAILURE_ALLOC;
if (uv_tcp_init(parasol_data.loop, parasol_data.tcp4) != 0)
return PARASOL_FAILURE_INIT;
//tcpfile
UvTcp4File = NULL;
UvTcp4File = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (UvTcp4File == NULL)
return Error("Cannot allocate uv TCP file");
if (uv_tcp_init(UvLoop, UvTcp4File) != 0)
return Error("Cannot init uv TCP file");
parasol_data.file4 = NULL;
parasol_data.file4 = (uv_tcp_t *)calloc(sizeof(uv_tcp_t), 1);
if (parasol_data.file4 == NULL)
return PARASOL_FAILURE_ALLOC;
if (uv_tcp_init(parasol_data.loop, parasol_data.file4) != 0)
return PARASOL_FAILURE_INIT;
//0 ENABLES Nagle's algorithm, and is default.
//uv_tcp_nodelay(UvTcp4, 0);
//uv_tcp_nodelay(parasol_data.tcp4, 0);
//Keepalive is DISABLED by default.
uv_tcp_keepalive(UvTcp4, 1, 0);
uv_tcp_keepalive(UvTcp4File, 1, 0);
uv_tcp_keepalive(parasol_data.tcp4, 1, 0);
uv_tcp_keepalive(parasol_data.file4, 1, 0);
//End
return 1;
return PARASOL_SUCCESS;
}
void TeardownUv()
void parasol_cleanup() //TeardownUv()
{
if (DoIpv6)
{
free(UvUdp6);
}
if (parasol_data.do_ipv6)
free(parasol_data.udp6);
free(UvUdp4);
free(UvLoop);
free(parasol_data.udp4);
free(parasol_data.loop);
}
//Suggestion is likely to be inaccurate for UDP, since the ethernet mtu is significantly smaller than 64kbs.
static uv_buf_t AllocateUDP(uv_handle_t* Handle, size_t Suggestion)
static uv_buf_t parasol_allocate_udp(uv_handle_t* Handle, size_t Suggestion)
{
// return uv_buf_init(malloc(Suggestion), Suggestion);
//return uv_buf_init(malloc(Suggestion), Suggestion);
return uv_buf_init(malloc(1600), 1600);
}
@ -137,32 +157,9 @@ static uv_buf_t AllocateTCP(uv_handle_t* Handle, size_t Suggestion)
return uv_buf_init(malloc(Suggestion), Suggestion);
}
//We've previous set this up in a general way, now we need to bind to an addr and start watching.
char InitUvUdp(char BindIP4[17], char BindIP6[40], unsigned short int Port)
{
//Receive
struct sockaddr_in6 UdpAddress6;
struct sockaddr_in UdpAddress4;
//struct sockaddr_in UdpSendAddress4;
//struct sockaddr_in6 UdpSendAddress6;
if (DoIpv6)
{
UdpAddress6 = uv_ip6_addr(BindIP6, Port);
uv_udp_bind6(UvUdp6, UdpAddress6, UV_UDP_IPV6ONLY);
uv_udp_recv_start(UvUdp6, AllocateUDP, ReceiveUdpPacket);
}
UdpAddress4 = uv_ip4_addr(BindIP4, Port);
uv_udp_bind(UvUdp4, UdpAddress4, 0);
uv_udp_recv_start(UvUdp4, AllocateUDP, ReceiveUdpPacket);
//ScrumbleDebug("Initialized UDP: %s %s %i", BindIP4, BindIP6, Port);
return 1;
}
//Init for server
char InitUvTcp(char BindIP4[17], char BindIP6[40], unsigned short int Port, unsigned short int FilePort)
parasol_return parasol_init_tcp(char BindIP4[17], char BindIP6[40], unsigned short int Port, unsigned short int FilePort) //InitUvTcp
{
//Receive
struct sockaddr_in6 TcpAddress6;
@ -170,34 +167,58 @@ char InitUvTcp(char BindIP4[17], char BindIP6[40], unsigned short int Port, unsi
struct sockaddr_in6 TcpAddress6File;
struct sockaddr_in TcpAddress4File;
if (DoIpv6)
if (parasol_data.do_ipv6)
{
TcpAddress6 = uv_ip6_addr(BindIP6, Port);
uv_tcp_bind6(UvTcp6, TcpAddress6);
if (uv_listen((uv_stream_t*) UvTcp6, 64, NewTcpConnection) != 0)
return Error("Cannot start listening to tcp 6");
uv_tcp_bind6(parasol_data.tcp6, TcpAddress6);
if (uv_listen((uv_stream_t*) parasol_data.tcp6, 64, NewTcpConnection) != 0)
return PARASOL_FAILURE_LISTEN;
TcpAddress6File = uv_ip6_addr(BindIP6, FilePort);
uv_tcp_bind6(UvTcp6File, TcpAddress6File);
if (uv_listen((uv_stream_t*) UvTcp6File, 64, NewTcpFileConnection) != 0)
return Error("Cannot start listening to tcp 6 file");
uv_tcp_bind6(parasol_data.file6, TcpAddress6File);
if (uv_listen((uv_stream_t*) parasol_data.file6, 64, NewTcpFileConnection) != 0)
return PARASOL_FAILURE_LISTEN;
}
TcpAddress4 = uv_ip4_addr(BindIP4, Port);
uv_tcp_bind(UvTcp4, TcpAddress4);
if (uv_listen((uv_stream_t*) UvTcp4, 64, NewTcpConnection) != 0)
return Error("Cannot start listening to tcp 4");
uv_tcp_bind(parasol_data.tcp4, TcpAddress4);
if (uv_listen((uv_stream_t*) parasol_data.tcp4, 64, NewTcpConnection) != 0)
return PARASOL_FAILURE_LISTEN;
TcpAddress4File = uv_ip4_addr(BindIP4, FilePort);
uv_tcp_bind(UvTcp4File, TcpAddress4File);
if (uv_listen((uv_stream_t*) UvTcp4File, 64, NewTcpFileConnection) != 0)
return Error("Cannot start listening to tcp 4 file");
uv_tcp_bind(parasol_data.file4, TcpAddress4File);
if (uv_listen((uv_stream_t*) parasol_data.file4, 64, NewTcpFileConnection) != 0)
return PARASOL_FAILURE_LISTEN;
//ScrumbleDebug("Initialized TCP: %s %s %i", BindIP4, BindIP6, Port);
return PARASOL_SUCCESS;
}
//We've previous set this up in a general way, now we need to bind to an addr and start watching.
parasol_return parasol_init_udp(char BindIP4[17], char BindIP6[40], unsigned short int Port)
{
//Receive
struct sockaddr_in6 UdpAddress6;
struct sockaddr_in UdpAddress4;
//struct sockaddr_in UdpSendAddress4;
//struct sockaddr_in6 UdpSendAddress6;
if (parasol_data.do_ipv6)
{
UdpAddress6 = uv_ip6_addr(BindIP6, Port);
uv_udp_bind6(parasol_data.udp6, UdpAddress6, UV_UDP_IPV6ONLY);
uv_udp_recv_start(parasol_data.udp6, parasol_allocate_udp, ReceiveUdpPacket);
}
UdpAddress4 = uv_ip4_addr(BindIP4, Port);
uv_udp_bind(parasol_data.udp4, UdpAddress4, 0);
uv_udp_recv_start(parasol_data.udp4, parasol_allocate_udp, ReceiveUdpPacket);
//ScrumbleDebug("Initialized UDP: %s %s %i", BindIP4, BindIP6, Port);
return 1;
}
//Tcp connect for client
char InitUvTcpClient(char ServerIP[40], unsigned short int Port)
parasol_return parasol_init_tcp_client(char ServerIP[40], unsigned short int Port) //InitUvTcpClient
{
//Receive
struct sockaddr_in6 TcpAddress6;
@ -205,11 +226,11 @@ char InitUvTcpClient(char ServerIP[40], unsigned short int Port)
uv_connect_t *UvConnect = (uv_connect_t *) malloc(sizeof(uv_connect_t));
uv_connect_t *UvFileConnect = (uv_connect_t *) malloc(sizeof(uv_connect_t));
if (DoIpv6)
if (parasol_data.do_ipv6)
{
TcpAddress6 = uv_ip6_addr(ServerIP, Port);
uv_tcp_connect6(UvConnect, UvTcp6, TcpAddress6, UvTcpConnect);
uv_tcp_connect6(UvFileConnect, UvTcp6File, TcpAddress6, UvTcpFileConnect);
uv_tcp_connect6(UvConnect, parasol_data.tcp6, TcpAddress6, UvTcpConnect);
uv_tcp_connect6(UvFileConnect, parasol_data.file6, TcpAddress6, UvTcpFileConnect);
//Seems a little counterintuitive to set this now, but it makes some sense.
//ScrumbleOptions.ConnectedToServer = 1;
//ScrumbleDebug("Connecting with TCP6: %s %i", ServerIP, Port);
@ -218,8 +239,8 @@ char InitUvTcpClient(char ServerIP[40], unsigned short int Port)
{
TcpAddress4 = uv_ip4_addr(ServerIP, Port);
uv_tcp_connect(UvConnect, UvTcp4, TcpAddress4, UvTcpConnect);
uv_tcp_connect(UvFileConnect, UvTcp4File, TcpAddress4, UvTcpFileConnect);
uv_tcp_connect(UvConnect, parasol_data.tcp4, TcpAddress4, UvTcpConnect);
uv_tcp_connect(UvFileConnect, parasol_data.file4, TcpAddress4, UvTcpFileConnect);
//Seems a little counterintuitive to set this now, but it makes some sense.
//ScrumbleOptions.ConnectedToServer = 1;
//ScrumbleDebug("Connecting with TCP4: %s %i", ServerIP, Port);
@ -231,31 +252,31 @@ char InitUvTcpClient(char ServerIP[40], unsigned short int Port)
//Callback for client
void UvTcpConnect(uv_connect_t *Connect, int Status)
{
TcpConnectStream = Connect->handle;
parasol_data.tcp_connect_stream = Connect->handle;
//ScrumbleDebug("Connected to server tcp!");
//Allocate our tcp data
TcpConnectStream->data = (UserTcpConnection *) calloc(sizeof(UserTcpConnection), 1);
parasol_data.tcp_connect_stream->data = (UserTcpConnection *) calloc(sizeof(UserTcpConnection), 1);
//Start reading the tcp connection
uv_read_start(TcpConnectStream, AllocateTCP, ReceiveTcpData);
uv_read_start(parasol_data.tcp_connect_stream, AllocateTCP, ReceiveTcpData);
//Probably want to send an ident packet here.
//SendIdentMessage(TcpConnectStream);
//SendIdentMessage(parasol_data.tcp_connect_stream);
free(Connect);
}
void UvTcpFileConnect(uv_connect_t *Connect, int Status)
{
TcpFileConnectStream = Connect->handle;
parasol_data.file_connect_stream = Connect->handle;
//ScrumbleDebug("Connected to server file tcp!");
//Allocate our tcp data
TcpFileConnectStream->data = (UserTcpFileConnection *) calloc(sizeof(UserTcpFileConnection), 1);
parasol_data.file_connect_stream->data = (UserTcpFileConnection *) calloc(sizeof(UserTcpFileConnection), 1);
//Start reading the tcp connection
uv_read_start(TcpFileConnectStream, AllocateTCP, ReceiveTcpFile);
uv_read_start(parasol_data.file_connect_stream, AllocateTCP, ReceiveTcpFile);
free(Connect);
}
@ -295,7 +316,7 @@ void WriteCleanup(uv_write_t* Request, int Status)
if (Request->data != NULL)
free(Request->data);
free(Request);
return;
return;
}
void WriteCleanupUdp(uv_udp_send_t* Request, int Status)
@ -305,7 +326,7 @@ void WriteCleanupUdp(uv_udp_send_t* Request, int Status)
//Generall sigpipe, or something similar. Other side closed the connection. We can't do anything about it, I think?
//}
free(Request);
return;
return;
}
void WriteCleanupUdpBatch(uv_udp_send_t* Request, int Status)
@ -318,7 +339,7 @@ void WriteCleanupUdpBatch(uv_udp_send_t* Request, int Status)
free(BufferData);
}
free(Request);
return;
return;
}
void WriteCleanupBatch(uv_write_t* Request, int Status)
@ -331,14 +352,14 @@ void WriteCleanupBatch(uv_write_t* Request, int Status)
free(BufferData);
}
free(Request);
return;
return;
}
void UdpSingleSendIP(char BindIP[40], unsigned short int Port, unsigned char *Message, short int Length)
{
struct sockaddr_in6 Addr6;
struct sockaddr_in Addr4;
if (DoIpv6)
if (parasol_data.do_ipv6)
{
Addr6 = uv_ip6_addr(BindIP, Port);
//UdpSingleSend((struct sockaddr *)&Addr6, Message, Length);
@ -348,7 +369,6 @@ void UdpSingleSendIP(char BindIP[40], unsigned short int Port, unsigned char *Me
Addr4 = uv_ip4_addr(BindIP, Port);
//UdpSingleSend((struct sockaddr *)&Addr4, Message, Length);
}
}
void UdpSingleSend(struct sockaddr *Address, uv_buf_t Buffer)//, char ListenForReplies)
@ -361,18 +381,18 @@ void UdpSingleSend(struct sockaddr *Address, uv_buf_t Buffer)//, char ListenForR
void UdpSingleSendInner(uv_udp_send_t *UvUdpSend, uv_buf_t *Buffer, struct sockaddr *Address)
{
if (DoIpv6 && Address->sa_family == AF_INET6)
uv_udp_send6(UvUdpSend, UvUdp6, Buffer, 1, *(struct sockaddr_in6 *)Address, WriteCleanupUdp);
if (parasol_data.do_ipv6 && Address->sa_family == AF_INET6)
uv_udp_send6(UvUdpSend, parasol_data.udp6, Buffer, 1, *(struct sockaddr_in6 *)Address, WriteCleanupUdp);
else if (Address->sa_family == AF_INET)
uv_udp_send(UvUdpSend, UvUdp4, Buffer, 1, *(struct sockaddr_in *)Address, WriteCleanupUdp);
uv_udp_send(UvUdpSend, parasol_data.udp4, Buffer, 1, *(struct sockaddr_in *)Address, WriteCleanupUdp);
}
void UdpSingleSendInnerBatch(uv_udp_send_t *UvUdpSend, uv_buf_t *Buffer, struct sockaddr *Address)
{
if (DoIpv6 && Address->sa_family == AF_INET6)
uv_udp_send6(UvUdpSend, UvUdp6, Buffer, 1, *(struct sockaddr_in6 *)Address, WriteCleanupUdpBatch);
if (parasol_data.do_ipv6 && Address->sa_family == AF_INET6)
uv_udp_send6(UvUdpSend, parasol_data.udp6, Buffer, 1, *(struct sockaddr_in6 *)Address, WriteCleanupUdpBatch);
else if (Address->sa_family == AF_INET)
uv_udp_send(UvUdpSend, UvUdp4, Buffer, 1, *(struct sockaddr_in *)Address, WriteCleanupUdpBatch);
uv_udp_send(UvUdpSend, parasol_data.udp4, Buffer, 1, *(struct sockaddr_in *)Address, WriteCleanupUdpBatch);
}
void NewTcpConnection(uv_stream_t *UvServer, int Status)
@ -382,13 +402,14 @@ void NewTcpConnection(uv_stream_t *UvServer, int Status)
}
uv_tcp_t *Client = (uv_tcp_t*) malloc(sizeof(uv_tcp_t));
uv_tcp_init(UvLoop, Client);
uv_tcp_init(parasol_data.loop, Client);
//Convert to stream
uv_stream_t *ClientAsStream = (uv_stream_t *)Client;
if (uv_accept(UvServer, ClientAsStream) == 0) //Attempt to accept client
{
ClientAsStream->data = (UserTcpConnection *) calloc(sizeof(UserTcpConnection), 1);
ClientAsStream->data = (UserTcpConnection *) calloc(sizeof(UserTcpConnection), 1);
//TODO - Check allocation
uv_read_start(ClientAsStream, AllocateTCP, ReceiveTcpData);
}
else
@ -406,14 +427,15 @@ void NewTcpFileConnection(uv_stream_t *UvServer, int Status)
}
uv_tcp_t *Client = (uv_tcp_t*) malloc(sizeof(uv_tcp_t));
uv_tcp_init(UvLoop, Client);
uv_tcp_init(parasol_data.loop, Client);
//Convert to stream
uv_stream_t *ClientAsStream = (uv_stream_t *)Client;
if (uv_accept(UvServer, (uv_stream_t*) Client) == 0) //Attempt to accept client
{
ClientAsStream->data = (UserTcpConnection *) calloc(sizeof(UserTcpConnection), 1);
ClientAsStream->data = (UserTcpConnection *) calloc(sizeof(UserTcpConnection), 1);
//TODO - Check allocation
uv_read_start((uv_stream_t*) Client, AllocateTCP, ReceiveTcpData);
}
else
@ -435,7 +457,7 @@ void ResetUserTcpConnection(UserTcpConnection *PacketData, unsigned int i)
PacketData->Message = NULL;
}
// PacketData->UserData = NULL;
//PacketData->UserData = NULL;
}
void ReceiveTcpData(uv_stream_t *Stream, ssize_t NumberRead, uv_buf_t Buffer)
@ -450,7 +472,7 @@ void ReceiveTcpData(uv_stream_t *Stream, ssize_t NumberRead, uv_buf_t Buffer)
{
//End of read! Cleanup
//ScrumbleDebug("End of Stream");
if (uv_last_error(UvLoop).code == UV_EOF)
if (uv_last_error(parasol_data.loop).code == UV_EOF)
{
goto ReceiveTcpDataError;
}
@ -620,7 +642,7 @@ void ReceiveTcpFile(uv_stream_t *Stream, ssize_t NumberRead, uv_buf_t Buffer)
if (NumberRead == -1)
{
//End of read! Cleanup
if (uv_last_error(UvLoop).code == UV_EOF)
if (uv_last_error(parasol_data.loop).code == UV_EOF)
{
goto ReceiveTcpFileError;
}
@ -705,6 +727,9 @@ void ReceiveTcpFile(uv_stream_t *Stream, ssize_t NumberRead, uv_buf_t Buffer)
goto ReceiveTcpFileExit;
}
//Returns 1 on a match
//Returns 0 when the sockets are different
//Returns -1 when handed a null socket
char CompareSockaddr(struct sockaddr *SocketA, const struct sockaddr *SocketB, char DoPort)
{
//If the pointers are the same, we ought to return true

Loading…
Cancel
Save