69 lines
1.5 KiB
C
69 lines
1.5 KiB
C
#ifndef OS_H
|
|
#define OS_H
|
|
|
|
#include "core.h"
|
|
|
|
// ### Memory ###
|
|
void *os_alloc(size_t capacity);
|
|
void os_reserve(void *ptr);
|
|
void os_decommit(void *ptr);
|
|
void os_free(void *ptr, size_t freeSize);
|
|
|
|
// ### File IO ###
|
|
string os_readEntireFile(Arena *arena, string filename);
|
|
bool os_writeEntireFile(Arena *arena, string filename, const byte *contents, size_t contentsLength);
|
|
bool os_fileAppend(Arena *arena, string filename, const byte *contents, size_t contentsLength);
|
|
|
|
// ### Standard IO ###
|
|
void os_print(StdStream target, const char *fmt, va_list argList);
|
|
|
|
// ### Multithreading ###
|
|
typedef struct OS_Thread OS_Thread;
|
|
struct OS_Thread {
|
|
uint64 id;
|
|
};
|
|
|
|
OS_Thread os_createThread(void *(*entry)(void *ctx), void *ctx);
|
|
|
|
// ### Network I/O ###
|
|
typedef struct Address Address;
|
|
struct Address;
|
|
|
|
typedef struct Socket Socket;
|
|
struct Socket;
|
|
|
|
typedef struct Client Client;
|
|
struct Client {
|
|
Address *clientAddressData;
|
|
Socket *socket;
|
|
};
|
|
DefineList(Client, Client);
|
|
|
|
typedef struct Server Server;
|
|
struct Server {
|
|
Arena *arena;
|
|
Address *serverAddressData;
|
|
uint32 serverPort;
|
|
Socket *socket;
|
|
ClientList clients;
|
|
bool listening;
|
|
};
|
|
|
|
typedef struct ServerInitInfo ServerInitInfo;
|
|
struct ServerInitInfo {
|
|
uint16 port;
|
|
uint32 concurrentClients;
|
|
uint64 memory;
|
|
};
|
|
|
|
Server serverInit(ServerInitInfo info);
|
|
void serverListen(Server *s);
|
|
Client *serverAccept(Server *s);
|
|
void serverClose(Server *s);
|
|
|
|
uint64 clientRead(Client *client, void *dest, size_t bytes);
|
|
void clientWrite(Client *client);
|
|
void clientClose(Client *client);
|
|
|
|
#endif
|