mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-11-24 06:42:23 -08:00
checkpoint on sockets layer
This commit is contained in:
1 parent
3e704eabb0
commit
3bab86e6af
14 files changed
+486
-38
No files matched your search
@@ -0,0 +1,96 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Helpers
|
||||
|
||||
internal SOCK_Endpoint
|
||||
sock_endpoint_from_string_port(String8 address, U16 port)
|
||||
{
|
||||
//- rjf: detect kind
|
||||
SOCK_EndpointKind kind = SOCK_EndpointKind_IPv4;
|
||||
{
|
||||
if(str8_find_needle(address, 0, s(":"), 0) < address.size)
|
||||
{
|
||||
kind = SOCK_EndpointKind_IPv6;
|
||||
}
|
||||
}
|
||||
|
||||
//- rjf: fill based on format
|
||||
SOCK_Endpoint ep = {0};
|
||||
ep.port = port;
|
||||
ep.kind = kind;
|
||||
switch(kind)
|
||||
{
|
||||
default:
|
||||
case SOCK_EndpointKind_IPv4:
|
||||
{
|
||||
U64 off = 0;
|
||||
U64 part_start_off = 0;
|
||||
for(;off < 4;)
|
||||
{
|
||||
U64 part_end_off = str8_find_needle(address, part_start_off+1, s("."), 0);
|
||||
String8 part = str8_substr(address, r1u64(part_start_off, part_end_off));
|
||||
U64 part_val = u64_from_str8(part, 10);
|
||||
ep.address_u8[off] = (U8)part_val;
|
||||
part_start_off = part_end_off+1;
|
||||
off += 1;
|
||||
if(part_end_off >= address.size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}break;
|
||||
case SOCK_EndpointKind_IPv6:
|
||||
{
|
||||
U64 off = 0;
|
||||
U64 part_start_off = 0;
|
||||
U64 double_colon_off = 0;
|
||||
for(;off < 8;)
|
||||
{
|
||||
U64 part_end_off = str8_find_needle(address, part_start_off+1, s(":"), 0);
|
||||
String8 part = str8_substr(address, r1u64(part_start_off, part_end_off));
|
||||
U64 part_val = u64_from_str8(part, 16);
|
||||
ep.address_u16[off] = (U16)part_val;
|
||||
part_start_off = part_end_off+1;
|
||||
if(part_end_off+1 < address.size && address.str[part_end_off+1] == ':')
|
||||
{
|
||||
double_colon_off = off;
|
||||
}
|
||||
off += 1;
|
||||
if(part_end_off >= address.size)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(off < 8 && double_colon_off < 8)
|
||||
{
|
||||
U64 shift_amt = 8 - off;
|
||||
MemoryCopy(&ep.address_u16[0] + double_colon_off + shift_amt, &ep.address_u16[0] + double_colon_off, sizeof(U16) * (off - double_colon_off));
|
||||
}
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
internal SOCK_Endpoint
|
||||
sock_endpoint_from_string(String8 address_and_port)
|
||||
{
|
||||
String8 addr = {0};
|
||||
U64 port_off = 0;
|
||||
if(address_and_port.size > 0 && address_and_port.str[0] == '[')
|
||||
{
|
||||
U64 addr_end_off = str8_find_needle(address_and_port, 1, s("]"), 0);
|
||||
addr = str8_substr(address_and_port, r1u64(1, addr_end_off));
|
||||
port_off = str8_find_needle(address_and_port, addr_end_off+1, s(":"), 0)+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
U64 colon_off = str8_find_needle(address_and_port, 0, s(":"), 0);
|
||||
port_off = colon_off + 1;
|
||||
addr = str8_prefix(address_and_port, colon_off);
|
||||
}
|
||||
String8 port_string = str8_skip(address_and_port, port_off);
|
||||
U16 port = u64_from_str8(port_string, 10);
|
||||
SOCK_Endpoint ep = sock_endpoint_from_string_port(addr, port);
|
||||
return ep;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef SOCKET_H
|
||||
#define SOCKET_H
|
||||
|
||||
#if !defined(SOCKET_PORT)
|
||||
# define SOCKET_PORT 7423
|
||||
#endif
|
||||
|
||||
typedef enum SOCK_Protocol
|
||||
{
|
||||
SOCK_Protocol_TCP,
|
||||
SOCK_Protocol_UDP,
|
||||
}
|
||||
SOCK_Protocol;
|
||||
|
||||
typedef U8 SOCK_EndpointKind;
|
||||
typedef enum SOCK_EndpointKindEnum
|
||||
{
|
||||
SOCK_EndpointKind_IPv4,
|
||||
SOCK_EndpointKind_IPv6,
|
||||
}
|
||||
SOCK_EndpointKindEnum;
|
||||
|
||||
typedef struct SOCK_Endpoint SOCK_Endpoint;
|
||||
struct SOCK_Endpoint
|
||||
{
|
||||
U16 port;
|
||||
SOCK_EndpointKind kind;
|
||||
U8 _pad_0;
|
||||
U32 _pad_1;
|
||||
union
|
||||
{
|
||||
U8 address_u8[16];
|
||||
U16 address_u16[8];
|
||||
};
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: Helpers
|
||||
|
||||
internal SOCK_Endpoint sock_endpoint_from_string_port(String8 address, U16 port);
|
||||
internal SOCK_Endpoint sock_endpoint_from_string(String8 address_and_port);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: @per_os_impl Top-Level Layer Calls
|
||||
|
||||
#if !defined(NEED_ASYNC)
|
||||
# define NEED_ASYNC 1
|
||||
#endif
|
||||
internal void sock_init(void);
|
||||
internal void sock_async_tick(void);
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: @per_os_impl Sends
|
||||
|
||||
internal U64 sock_send(U8 *ptr, U64 size, SOCK_Protocol *protocol_in, SOCK_Endpoint *endpoint_in, U64 endt_us);
|
||||
#define sock_send_struct(ptr, protocol_in, endpoint_in, endt_us) sock_send((ptr), sizeof(*(ptr)), (endpoint_in), (endt_us))
|
||||
|
||||
////////////////////////////////
|
||||
//~ rjf: @per_os_impl Receives
|
||||
|
||||
internal U64 sock_recv(U8 *ptr, U64 size, SOCK_Protocol *protocol_out, SOCK_Endpoint *endpoint_out, U64 endt_us);
|
||||
#define sock_recv_struct(ptr, protocol_out, endpoint_out, endt_us) sock_recv((ptr), sizeof(*(ptr)), (endpoint_out), (endt_us))
|
||||
|
||||
#endif // SOCKET_H
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#include "socket.c"
|
||||
#if OS_WINDOWS
|
||||
# include "win32/socket/win32_socket.c"
|
||||
#else
|
||||
# include "socket_stub.c"
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef SOCKET_INC_H
|
||||
#define SOCKET_INC_H
|
||||
|
||||
#include "socket.h"
|
||||
#if OS_WINDOWS
|
||||
# include "win32/socket/win32_socket.h"
|
||||
#else
|
||||
# include "socket_stub.h"
|
||||
#endif
|
||||
|
||||
#endif // SOCKET_INC_H
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
internal void sock_init(void){}
|
||||
internal void sock_async_tick(void){}
|
||||
internal U64 sock_send(U8 *ptr, U64 size, SOCK_Protocol *protocol_in, SOCK_Endpoint *endpoint_in, U64 endt_us){return 0;}
|
||||
internal U64 sock_recv(U8 *ptr, U64 size, SOCK_Protocol *protocol_in, SOCK_Endpoint *endpoint_in, U64 endt_us){return 0;}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright (c) Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef SOCKET_STUB_H
|
||||
#define SOCKET_STUB_H
|
||||
|
||||
#endif // SOCKET_STUB_H
|
||||
Reference in new issue
Block a user