37 lines
1.4 KiB
C
Executable File
37 lines
1.4 KiB
C
Executable File
#pragma once
|
|
#include "endpoint.h"
|
|
#include "tlibc/errors.h"
|
|
#include "tlibc/collections/Array.h"
|
|
|
|
typedef enum SocketShutdownType {
|
|
SocketShutdownType_Receive = 0,
|
|
SocketShutdownType_Send = 1,
|
|
SocketShutdownType_Both = 2,
|
|
} SocketShutdownType;
|
|
|
|
typedef enum SocketRecvFlag {
|
|
SocketRecvFlag_None = 0,
|
|
SocketRecvFlag_Peek = 0b1 /* next recv call will read the same data */,
|
|
SocketRecvFlag_WholeBuffer = 0b10 /* waits until buffer is full */,
|
|
} SocketRecvFlag;
|
|
|
|
typedef i64 Socket;
|
|
|
|
#define SOCKET_TIMEOUT_MS_DEFAULT 5000
|
|
#define SOCKET_TIMEOUT_MS_INFINITE 0
|
|
|
|
Result(Socket) socket_open_TCP();
|
|
void socket_close(Socket s);
|
|
Result(void) socket_shutdown(Socket s, SocketShutdownType direction);
|
|
Result(void) socket_setTimeout(Socket s, u32 ms);
|
|
|
|
Result(void) socket_bind(Socket s, EndpointIPv4 local_end);
|
|
Result(void) socket_listen(Socket s, i32 backlog);
|
|
Result(Socket) socket_accept(Socket listening_sock, NULLABLE(EndpointIPv4*) remote_end);
|
|
Result(void) socket_connect(Socket s, EndpointIPv4 remote_end);
|
|
|
|
Result(void) socket_send(Socket s, Array(u8) buffer);
|
|
Result(void) socket_sendto(Socket s, Array(u8) buffer, EndpointIPv4 dst);
|
|
Result(i32) socket_recv(Socket s, Array(u8) buffer, SocketRecvFlag flags);
|
|
Result(i32) socket_recvfrom(Socket s, Array(u8) buffer, SocketRecvFlag flags, NULLABLE(EndpointIPv4*) remote_end);
|