Kore 3
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1#ifndef KORE_NETWORK_SOCKET_HEADER
2#define KORE_NETWORK_SOCKET_HEADER
3
4#include <kore3/global.h>
5
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14typedef enum kore_socket_protocol { KORE_SOCKET_PROTOCOL_UDP, KORE_SOCKET_PROTOCOL_TCP } kore_socket_protocol;
15
16typedef enum kore_socket_family { KORE_SOCKET_FAMILY_IP4, KORE_SOCKET_FAMILY_IP6 } kore_socket_family;
17
18#ifdef KORE_MICROSOFT
19#if defined(_WIN64)
20typedef unsigned __int64 UINT_PTR, *PUINT_PTR;
21#else
22#if !defined _W64
23#define _W64
24#endif
25typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
26#endif
27typedef UINT_PTR SOCKET;
28#endif
29
30typedef struct kore_socket {
31#ifdef KORE_MICROSOFT
32 SOCKET handle;
33#else
34 int handle;
35#endif
36 uint32_t host;
37 uint32_t port;
38 kore_socket_protocol protocol;
39 kore_socket_family family;
40 bool connected;
42
43typedef struct kore_socket_parameters {
44 bool non_blocking;
45 bool broadcast;
46 bool tcp_no_delay;
48
54
63KORE_FUNC void kore_socket_init(kore_socket *socket);
64
74KORE_FUNC bool kore_socket_set(kore_socket *socket, const char *host, int port, kore_socket_family family, kore_socket_protocol protocol);
75
80KORE_FUNC void kore_socket_destroy(kore_socket *socket);
81
90KORE_FUNC bool kore_socket_open(kore_socket *socket, const kore_socket_parameters *parameters);
91
100KORE_FUNC bool kore_socket_select(kore_socket *socket, uint32_t waittime, bool read, bool write);
101
102/*Typically these are server actions.*/
103KORE_FUNC bool kore_socket_bind(kore_socket *socket);
104KORE_FUNC bool kore_socket_listen(kore_socket *socket, int backlog);
105KORE_FUNC bool kore_socket_accept(kore_socket *socket, kore_socket *new_socket, unsigned *remote_address, unsigned *remote_port);
106
107/*Typically this is a client action.*/
108KORE_FUNC bool kore_socket_connect(kore_socket *socket);
109
110KORE_FUNC int kore_socket_send(kore_socket *socket, const uint8_t *data, int size);
111KORE_FUNC int kore_socket_send_address(kore_socket *socket, unsigned address, int port, const uint8_t *data, int size);
112KORE_FUNC int kore_socket_send_url(kore_socket *socket, const char *url, int port, const uint8_t *data, int size);
113KORE_FUNC int kore_socket_receive(kore_socket *socket, uint8_t *data, int maxSize, unsigned *from_address, unsigned *from_port);
114
121KORE_FUNC unsigned kore_url_to_int(const char *url, int port);
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif
Provides basic functionality that's used all over the place. There's usually no need to manually incl...
KORE_FUNC void kore_socket_parameters_set_defaults(kore_socket_parameters *parameters)
Initializes a socket-options-object to the default parameters.
KORE_FUNC void kore_socket_init(kore_socket *socket)
Initializes a socket-object. To set the host and port use kore_socket_set. Host will be localhost Por...
KORE_FUNC bool kore_socket_open(kore_socket *socket, const kore_socket_parameters *parameters)
Opens a socket-connection.
KORE_FUNC bool kore_socket_set(kore_socket *socket, const char *host, int port, kore_socket_family family, kore_socket_protocol protocol)
Sets the sockets properties.
KORE_FUNC unsigned kore_url_to_int(const char *url, int port)
Resolves a DNS-entry to an IP and returns its integer representation.
KORE_FUNC bool kore_socket_select(kore_socket *socket, uint32_t waittime, bool read, bool write)
For use with non-blocking sockets to try to see if we are connected.
KORE_FUNC void kore_socket_destroy(kore_socket *socket)
Destroys a socket-object.
Definition socket.h:43
Definition socket.h:30