Kore 3
Loading...
Searching...
No Matches
socket.h File Reference

Provides low-level network-communication via UDP or TCP-sockets. More...

#include <kore3/global.h>

Go to the source code of this file.

Data Structures

struct  kore_socket
struct  kore_socket_parameters

Typedefs

typedef enum kore_socket_protocol kore_socket_protocol
typedef enum kore_socket_family kore_socket_family
typedef struct kore_socket kore_socket
typedef struct kore_socket_parameters kore_socket_parameters

Enumerations

enum  kore_socket_protocol { KORE_SOCKET_PROTOCOL_UDP , KORE_SOCKET_PROTOCOL_TCP }
enum  kore_socket_family { KORE_SOCKET_FAMILY_IP4 , KORE_SOCKET_FAMILY_IP6 }

Functions

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 Port will be 8080 Family will be IPv4 Protocol will be TCP.
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 void kore_socket_destroy (kore_socket *socket)
 Destroys a socket-object.
KORE_FUNC bool kore_socket_open (kore_socket *socket, const kore_socket_parameters *parameters)
 Opens a socket-connection.
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 bool kore_socket_bind (kore_socket *socket)
KORE_FUNC bool kore_socket_listen (kore_socket *socket, int backlog)
KORE_FUNC bool kore_socket_accept (kore_socket *socket, kore_socket *new_socket, unsigned *remote_address, unsigned *remote_port)
KORE_FUNC bool kore_socket_connect (kore_socket *socket)
KORE_FUNC int kore_socket_send (kore_socket *socket, const uint8_t *data, int size)
KORE_FUNC int kore_socket_send_address (kore_socket *socket, unsigned address, int port, const uint8_t *data, int size)
KORE_FUNC int kore_socket_send_url (kore_socket *socket, const char *url, int port, const uint8_t *data, int size)
KORE_FUNC int kore_socket_receive (kore_socket *socket, uint8_t *data, int maxSize, unsigned *from_address, unsigned *from_port)
KORE_FUNC unsigned kore_url_to_int (const char *url, int port)
 Resolves a DNS-entry to an IP and returns its integer representation.

Detailed Description

Provides low-level network-communication via UDP or TCP-sockets.

Function Documentation

◆ kore_socket_destroy()

KORE_FUNC void kore_socket_destroy ( kore_socket * socket)

Destroys a socket-object.

Parameters
socketThe socket to destroy

◆ kore_socket_init()

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 Port will be 8080 Family will be IPv4 Protocol will be TCP.

Parameters
socketThe socket to initialize

◆ kore_socket_open()

KORE_FUNC bool kore_socket_open ( kore_socket * socket,
const kore_socket_parameters * parameters )

Opens a socket-connection.

Parameters
socketThe socket-object to use
protocolThe protocol to use
portThe port to use
optionsThe options to use
Returns
Whether the socket-connection could be opened

◆ kore_socket_parameters_set_defaults()

KORE_FUNC void kore_socket_parameters_set_defaults ( kore_socket_parameters * parameters)

Initializes a socket-options-object to the default parameters.

Parameters
optionsThe new default options

◆ kore_socket_select()

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.

Parameters
socketThe socket-object to use
waittimeThe amount of time in seconds the select function will timeout.
readCheck if the socket is ready to be read from.
writeCheck if the socket is ready to be written to.
Returns
Whether the socket-connection can read or write or checks both.

◆ kore_socket_set()

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.

Parameters
socketThe socket-object to use
hostThe host to use as IP or URL
portThe port to use
familyThe IP-family to use
protocolThe protocol to use
Returns
Whether the socket was set correctly

◆ kore_url_to_int()

KORE_FUNC unsigned kore_url_to_int ( const char * url,
int port )

Resolves a DNS-entry to an IP and returns its integer representation.

Parameters
url
port
Returns