postnummer-app/backend/tcp.h

33 lines
951 B
C
Raw Permalink Normal View History

2023-02-10 16:39:04 +00:00
#ifndef TCP_H
#define TCP_H
#include <stdbool.h>
#include <stdint.h>
#ifdef _WIN32
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#else
#include <sys/types.h>
#endif
void tcp_global_initialize_sockets(void);
typedef struct TcpServer TcpServer;
typedef struct TcpConnection TcpConnection;
// returns NULL on errors, and prints the error
TcpServer* tcp_server_create(const char* ip, uint16_t port);
void tcp_server_destroy(TcpServer* server);
// returns NULL on errors, and prints the error
TcpConnection* tcp_server_accept(TcpServer* server);
void tcp_connection_destroy(TcpConnection* connection);
// returns amount transmittet >0 on success, ==0 if client was disconnected, and <0 on error
ssize_t tcp_recieve(TcpConnection* connection, uint8_t* data, size_t amount);
// returns amount transmittet >0 on success, ==0 if client was disconnected, and <0 on error
ssize_t tcp_send(TcpConnection* connection, uint8_t* data, size_t amount);
#endif