Reliable UDP transport library

© Freebox, Nicolas Pouillon, 11 Oct 2011

Overview  

Rudp is a library aimed at adding reliability features to UDP.

  • Deliver packets in order

  • Mark certain packets as reliable, retransmit them

  • Drop unordered packets

  • Implement server and client models

Table of contents  

1 Objects management

Life cycle  

Complex objects of the library have a common live cycle:

  • Allocation is left to the user.

  • Initialization is done with rudp_<object>_init, it initializes internal state and may allocate private data. An initialized object is valid for usage, and can be reused.

  • Deinitialization is done with rudp_<object>_deinit. This function must be called before memory relase.

  • Memory release is left to the user.

Callbacks  

When Librudp objects have to hand data back to the application code, they use a callback mechanism. Callbacks are registered on object initialization.

For instance with a server, an user code could be:

static
void my_handle_packet(
struct rudp_server *server,
struct rudp_peer *peer,
struct rudp_packet_chain *packet)
{
/* Do something with the packet */
}

static
void my_link_info(
struct rudp_server *server,
struct rudp_peer *peer,
struct rudp_link_info *info)
{
/* Do something with the link info */
}

static
void my_peer_new(
struct rudp_server *server,
struct rudp_peer *peer)
{
/* Do something with the link peer */
}

static
void my_peer_dropped(
struct rudp_server *server,
struct rudp_peer *peer)
{
/* Do something with the link peer */
}

static const struct rudp_server_handler my_server_handler =
{
.handle_packet = my_handle_packet,
.link_info = my_link_info,
.peer_dropped = my_peer_dropped,
.peer_new = my_peer_new,
};

/* Server initialization */
void my_server_init()
{
struct rudp_server *server = malloc(sizeof(*server));
struct ela_el *el = ...;

rudp_error_t err = rudp_server_init(server, el, &my_server_handler);
}

Memory management  

Memory allocation for the objects can be done as user likes most. User may embed rudp objects it allocates itself in a bigger structure like:

struct my_server
{
struct rudp_server server;
struct my_user_data;
};

static void my_handle_packet(
struct rudp_server *_server,
struct rudp_peer *peer,
struct rudp_packet_chain *packet)
{
struct my_server *server = (struct my_server *)_server;

/* Do something with server->my_user_data and packet */
}

/* Initialize the server */

void my_server_init()
{
struct my_server *server;

/* allocate space for server */
server = malloc(sizeof(*server));

/* check allocation error */

/* find an ELA implementation */
struct ela_el *el = ...;

rudp_error_t err =
rudp_server_init(&server->server, el, &my_server_handler);

/* handle errors, be happy */
}

2 User API

Master state  

Master library state holds context used for administrative purposes of the library. It handles:

  • Event loop abstraction handling (though libela)

  • Memory management

  • Logging

Master library state must be passed to all library objects initialization.

A libela context must be initialized before the rudp context. See libela documentation for more information.

When a handler is defined for logging, it gets all the messages from the library. If user wants to filter messages, it can use the level parameter. .

Memory allocation is handler through alloc/free-like functions. for functions to implement.

Librudp provides sane defaults for the needed handlers, not reporting any log messages, and using malloc and free from the system's libc. Such handler is defined as RUDP_HANDLER_DEFAULT.

Sample usage:

struct rudp rudp;
struct ela_el *el = ...;

rudp_init(&rudp, el, RUDP_HANDLER_DEFAULT);

// allocate and initialize some objects

// run your event loop

// deinitialize and free the objects

rudp_deinit(&rudp);

See also enum rudp_log_level enum and struct rudp_handler struct.

Utilities  

Time  

Time handling is done through the rudp_time_t type. This type is a scalar and can be manipulated with usual scalar operations.

The only functions declared for usage with rudp_time_t are rudp_timestamp and rudp_timestamp_to_timeval.

Erros  

Error handling avoids usage of the errno C global. Error codes are directly returned from functions where relevant. They use the common rudp_error_t type. This type only means the value is an error. Error codes are taken from errno definition.

Addresses  

Addresses are abstracted in the library. Addresses are represented through the struct rudp_address.

Addresses are objects with the same life cycle as most other complex objects of the library. Before use, address structures must be initialized with rudp_address_init, and after use, they must be cleaned with rudp_address_deinit.

Addresses may be set 3 ways:

After the address is correctly setup, user code may use rudp_address_get to retrieve a struct sockaddr containing the address.

In order to walk through the resolved addresses, user may call rudp_address_next. This loops through the available addresses corresponding to an hostname.

Client/server model  

Client  

Client connects to a server. As long as the connection is established, data can be exchanged both ways, either reliably or not.

For connecting, It either uses an explicit constant IPv4 or IPv6 address, or an hostname to resolve.

Client contexts use the same life cycle as other complex objects of the library. Before use, client contexts must be initialized with rudp_client_init, and after use, they must be cleaned with rudp_client_deinit.

An initialized but not yet connected Client context must have its server address setup with any of the following functions: rudp_client_set_hostname, rudp_client_set_ipv4 or rudp_client_set_ipv6.

Once the server address is setup properly, Client context can be connected with rudp_client_connect. After successful handshake with the server, the rudp_client_handler::connected handler is called back.

Either because of a connection timeout or because of server disconnection the rudp_client_handler::server_lost handler is called back.

Anytime afer call to rudp_client_connect and until the rudp_client_handler::server_lost handler is called, user may ask for disconnection with rudp_client_close.

Sample usage:

// assuming you have a valid rudp context here:
struct rudp *rudp;

struct rudp_client client;

rudp_client_init(&client, rudp, &my_client_handlers);

// set the server address and connect
rudp_client_set_ipv4(&client, ...);
rudp_client_connect(&client);

// run your event loop

rudp_client_close(&client);
rudp_client_deinit(&client);

Server  

Server binds to a given socket address and waits for clients to connect. For binding, It either uses an explicit constant IPv4 or IPv6 address, or an hostname to resolve.

When a client connects, as long as the connection is established, data can be exchanged both ways, either reliably or not. User code gets notified of clients (un)connecting.

Server contexts use the same life cycle as other complex objects of the library. Before use, server contexts must be initialized with rudp_server_init, and after use, they must be cleaned with rudp_server_deinit.

An initialized but not yet bound Server context must have its server address setup with any of the following functions: rudp_server_set_hostname, rudp_server_set_ipv4 or rudp_server_set_ipv6.

Once the server address is setup properly, Server context can be bound with rudp_server_bind. After successful binding, the server waits for clients and data packets.

User code may store an user-handled user data pointer inside the peer structures associated to a server context. This can be done through the rudp_server_peer_data_set and rudp_server_peer_data_get functions.

Sample usage:

// assuming you have a valid rudp context here:
struct rudp *rudp;

struct rudp_server server;

rudp_server_init(&server, rudp, &my_server_handlers);

// set the address and bind
rudp_server_set_ipv4(&server, ...);
rudp_server_bind(&server);

// run your event loop

rudp_server_close(&server);
rudp_server_deinit(&server);

3 Internal library implementation

Peer  

Peer is the symmetrical implementation of the protocol. A Peer context handles the low-level protocol (with retransmits and ACKs).

Peer context does not directly handle the transport and is abstract from the network code.

Peer contexts use the same life cycle as other complex objects of the library. Before use, peer contexts must be initialized with rudp_peer_init, and after use, they must be cleaned with rudp_peer_deinit.

Either because of a connection timeout or because of relevant command is received, disconnection can happend and the rudp_peer_handler::dropped handler is called back.

Endpoint  

Endpoint is an abstration over a system socket. It handles sending and receiving of packets.

Endpoint contexts use the same life cycle as other complex objects of the library. Before use, endpoint contexts must be initialized with rudp_endpoint_init, and after use, they must be cleaned with rudp_endpoint_deinit.

4 Protocol

Network protocol  

Features  

Rudp has the following features:

  • Strict in-order delivery of packets.

  • Packets may be reliable or not, this is a per-packet setting.

  • Packets cannot be delivered to the application twice.

Packet header  

Offset (bit)
Size (bits)
Name
Description
0
8
CMD
Command
8
5
RES
Reserved
13
1
RET
Retransmitted flag
14
1
ACK
Acknowledge flag
15
1
REL
Reliable flag
16
16
ACK_SEQ
Acknowledge sequence number
32
16
REL_SEQ
Reliable sequence number
48
16
UNR_SEQ
Unreliable sequence number

On each transmitted packet, REL is optional. If set, packet is reliable and must be acknowledged by peer.

A reliable packet must have a REL_SEQ immediately after the previous reliable packet sent. UNR_SEQ must be 0.

Acknowledge of a reliable packet may be piggybacked in any packet going the other way (reliable or not). It is present when ACK is set. Acknowledged sequence number is in ACK_SEQ.

An unreliable packet has no REL flag set. It has the same REL_SEQ number as the latest reliable packet transmitted, and is assigned next UNR_SEQ number.

RET flag is present for reliable packets that were already sent on the wire at least once before.

Retransmits  

Receiver may loose any unreliable packet harmlessly (reason may be loss of packet, unsequenced packet, etc.).

Reliable packets may be lost any time, but must be retransmitted by the Sender until acknowledged.

If a Receiver gets an out-of-sequence reliable packet, it must drop it until the transmitter resends the expected in-sequence packet.

If a Receiver gets a reliable packet twice (or more), it must acknowledge its sequence number again, but must not interpret the contents again.

Connection handshake  

Low-level protocol is peer-to-peer. As UDP is not connected, one of the two involved peers must send a packet first. Any of the two can do it. This packet is expected to be containing a RUDP_CMD_CONN_REQ command with reliable sequence number to a random value.. This packet should be reliable, i.e. imply retransmits in the sender's code.

Peer is expected to answer with an unreliable packet containing both an ACK and a RUDP_CMD_CONN_RSP packet. Its sequence number must be random as well. If the response packet is lost in transit, handshake will fail and must be started over. This is intended.

After these two packets are exchanged, connection is established. Each peer takes the sequence number it received in first packet as granted. This is only true for first packet.

On an established connection, 3 main types of packets may transit:

  • Ping/Pong packets

  • Noop packets

  • Data packets

Packet types  

Noop  

Noop packets have the RUDP_CMD_NOOP command value. They serve no applicative purpose and should contain no data. Nevertheless, Noop packets can be reliably sent (forcing it to be acknowledged), and conveys an acknowledge sequence number.

This packet type is well suited for feeding acknowledges.

Ping/Pong  

Ping packets have the RUDP_CMD_PING command value. They should be sent reliably, but do not necessarily imply a PONG packet. An acknowledge is still expected though:

Ping payload is optional and must be copied verbatim in the matching Pong packet. Ping Sender (thus Pong receiver) can use it for statistics purposes.

If Ping packet had to be retransmitted by the sender to reach its peer (see RUDP_OPT_RETRANSMITTED), it may contain outdated information. Therefore, a peer is expected NOT to send Pong packet marked retransmitted. Nevertheless, Peer must always acknowledge the packet sequence.

This way, Ping is actually an "echo" request. It makes a payload go both ways. If the sender stack needs an acknowledge, it must say so.

Implementation detail: Current peer implementation uses Ping to evaluate the link RTT and check the link validity at the same time. It puts a timestamp in the sent packet and waits for it to come back. This behaviour may evolve in future revisions of the library.

Data  

Data packets have the RUDP_CMD_APP (or any superior) command value. They are sent reliably or not, depending on user's needs. Their semantics are left to the user.

Packet C structure  

Librudp packet format is designed to support the features of the protocol. All packets contain a fixed header containing:

  • a command

  • some flags

  • a field for acking received packets sequence numbers

  • two fields for outgoing sequence numbers.

Data follows the header, in an arbitrary format. Some commands require fixed data. See relevant command definitions.

As the 1-byte command code is under-used, user can use any code equal or above RUDP_CMD_APP.

5 Headers

Header list  

NameDescription
rudp/address.hInternet address (IPv4/IPv6) abstraction, with resolving
rudp/client.hClient implementation
rudp/endpoint.hNetwork endpoint (socket handling)
rudp/error.hCommon error representation
rudp/packet.hNetwork packet structure
rudp/peer.hPeer implementation
rudp/rudp.hMaster library state
rudp/server.hServer implementation
rudp/time.hUniform time representation

rudp/address.h header reference
[Address module]

Internet address (IPv4/IPv6) abstraction, with resolving More

Header inclusion  

Members  

Type  

Functions  

Description  

Addresses are abstracted in the library. Addresses are represented through the struct rudp_address.

Addresses are objects with the same life cycle as most other complex objects of the library. Before use, address structures must be initialized with rudp_address_init, and after use, they must be cleaned with rudp_address_deinit.

Addresses may be set 3 ways:

After the address is correctly setup, user code may use rudp_address_get to retrieve a struct sockaddr containing the address.

In order to walk through the resolved addresses, user may call rudp_address_next. This loops through the available addresses corresponding to an hostname.

Members detail  

#define RUDP_ADDRESS_H_  

This macro is declared in rudp/address.h source file, line 13.

#define RUDP_IPV4_ONLY  

This macro is declared in rudp/address.h source file, line 53.

#define RUDP_IPV6_ONLY  

This macro is declared in rudp/address.h source file, line 54.

#define RUDP_IP_ANY  

This macro is declared in rudp/address.h source file, line 55.

#define RUDP_NO_IPV4  

This macro is declared in rudp/address.h source file, line 51.

#define RUDP_NO_IPV6  

This macro is declared in rudp/address.h source file, line 52.

struct rudp_address  

This struct is declared in rudp/address.h source file, line 69.

this struct is an abstract representation of an address.

Addresses are objects with the same life cycle as most other complex objects of the library. Before use, address structures must be initialized with rudp_address_init, and after use, they must be cleaned with rudp_address_deinit.

int rudp_address_compare(const struct rudp_address *address, const struct sockaddr_storage *addr)  

This function is declared in rudp/address.h source file, line 211.

this function compares the address against another address

Parameters list:

  • address: Address structure to compare
  • addr: System address to compare to

The return value is 0 if they match, another value otherwise

void rudp_address_deinit(struct rudp_address *addr)  

This function is declared in rudp/address.h source file, line 200.

this function releases all data internally referenced by an address structure.

Parameters list:

  • addr: The address structure to deinit

rudp_error_t rudp_address_get(const struct rudp_address *addr, const struct sockaddr_storage **address, socklen_t *size)  

This function is declared in rudp/address.h source file, line 154.

this function gets a pointer to the socket() api-compatible structure. Pointer is owner by the address structure and is valid until next call to rudp_address_set_* or rudp_address_next.

As this function only takes a reference, this function has a o(1) complexity and can be called as often as needed.

Parameters list:

  • addr: Address to get the sockaddr structure from
  • address: (out) System-compatible address structure
  • size: (out) Size of the address structure

The return value is 0 on success, RUDP_ENOADDR if resolution failed, RUDP_EBACKEND on unhandled errors

void rudp_address_init(struct rudp_address *addr, struct rudp *rudp)  

This function is declared in rudp/address.h source file, line 191.

this function initializes an address structure for future usage. This function must be called before any other address-related function on the structure.

Parameters list:

  • addr: The address structure to initialize
  • rudp: A valid rudp context

rudp_error_t rudp_address_next(struct rudp_address *addr)  

This function is declared in rudp/address.h source file, line 134.

this function takes the next usable address in the resolver state. This call only makes sense for addresses using rudp_address_set_hostname.

Parameters list:

  • addr: Address to walk in

The return value is 0 on success, RUDP_ENOADDR if resolution failed, RUDP_EBACKEND on unhandled errors

rudp_error_t rudp_address_set_hostname(struct rudp_address *addr, const char *hostname, const uint16_t port, uint32_t ip_flags)  

This function is declared in rudp/address.h source file, line 108.

this function specifies a hostname to be resolved with system resolver, and uses the results in turn. This can implement a round-roubin service usage.

Parameters list:

  • addr: The address structure
  • hostname: Hostname to resolve
  • port: Numeric target port (machine order)
  • ip_flags: RUDP_IPV4_ONLY, RUDP_IPV6_ONLY or RUDP_IP_ANY

The return value is 0 on success, RUDP_EBACKEND if resolution failed, RUDP_ENOMEM if allocation failed

void rudp_address_set_ipv4(struct rudp_address *addr, const struct in_addr *address, const uint16_t port)  

This function is declared in rudp/address.h source file, line 167.

this function specifies an IPv4 address and port

Parameters list:

  • addr: The address structure
  • address: IPv4 to use (usual struct in_addr order)
  • port: Numeric target port (machine order)

void rudp_address_set_ipv6(struct rudp_address *addr, const struct in6_addr *address, const uint16_t port)  

This function is declared in rudp/address.h source file, line 180.

this function specifies an IPv6 address and port

Parameters list:

  • addr: The address structure
  • address: IPv6 to use (usual struct in6_addr order)
  • port: Numeric target port (machine order)

const char * rudp_address_text(struct rudp_address *addr)  

This function is declared in rudp/address.h source file, line 121.

this function gets a pointer to a textual representation of the address.

As this function only takes a reference, this function has a cost only on the first call, and then has a o(1) complexity and can be called as often as needed.

Parameters list:

  • addr: Address structure

The return value is a valid constant string

rudp/client.h header reference
[Client module]

Client implementation More

Header inclusion  

Members  

Types  

Functions  

  • rudp_error_t rudp_client_close(struct rudp_client *client)
  • rudp_error_t rudp_client_connect(struct rudp_client *client)
  • rudp_error_t rudp_client_deinit(struct rudp_client *client)
  • rudp_error_t rudp_client_init(struct rudp_client *client, struct rudp *rudp, const struct rudp_client_handler *handler)
  • rudp_error_t rudp_client_send(struct rudp_client *client, int reliable, int command, const void *data, const size_t size)
  • rudp_error_t rudp_client_set_hostname(struct rudp_client *client, const char *hostname, const uint16_t port, uint32_t ip_flags)
  • void rudp_client_set_ipv4(struct rudp_client *client, const struct in_addr *address, const uint16_t port)
  • void rudp_client_set_ipv6(struct rudp_client *client, const struct in6_addr *address, const uint16_t port)

Description  

Client connects to a server. As long as the connection is established, data can be exchanged both ways, either reliably or not.

For connecting, It either uses an explicit constant IPv4 or IPv6 address, or an hostname to resolve.

Client contexts use the same life cycle as other complex objects of the library. Before use, client contexts must be initialized with rudp_client_init, and after use, they must be cleaned with rudp_client_deinit.

An initialized but not yet connected Client context must have its server address setup with any of the following functions: rudp_client_set_hostname, rudp_client_set_ipv4 or rudp_client_set_ipv6.

Once the server address is setup properly, Client context can be connected with rudp_client_connect. After successful handshake with the server, the rudp_client_handler::connected handler is called back.

Either because of a connection timeout or because of server disconnection the rudp_client_handler::server_lost handler is called back.

Anytime afer call to rudp_client_connect and until the rudp_client_handler::server_lost handler is called, user may ask for disconnection with rudp_client_close.

Sample usage:

// assuming you have a valid rudp context here:
struct rudp *rudp;

struct rudp_client client;

rudp_client_init(&client, rudp, &my_client_handlers);

// set the server address and connect
rudp_client_set_ipv4(&client, ...);
rudp_client_connect(&client);

// run your event loop

rudp_client_close(&client);
rudp_client_deinit(&client);

Members detail  

#define RUDP_CLIENT_H_  

This macro is declared in rudp/client.h source file, line 13.

struct rudp_client  

This struct is declared in rudp/client.h source file, line 155.

this struct is a client context structure. User should not use its fields directly.

Clients are objects with the same life cycle as most other complex objects of the library. Before use, client contexts must be initialized with rudp_client_init, and after use, they must be cleaned with rudp_client_deinit.

An initialized client context can try connection to a server with rudp_client_connect, and a connected client context can be closed with rudp_client_close. A closed client context stays initialized.

rudp_error_t rudp_client_close(struct rudp_client *client)  

This function is declared in rudp/client.h source file, line 203.

this function cleanly drops connection to the server and closes all associated sockets.

Parameters list:

  • client: A connected (or currently trying to connect) client context structure

The return value is a possible error

rudp_error_t rudp_client_connect(struct rudp_client *client)  

This function is declared in rudp/client.h source file, line 191.

this function tries to establish a connection with the server. Server address can be set with any of the rudp_client_set_hostname, rudp_client_set_ipv4 or rudp_client_set_ipv6.

Parameters list:

  • client: An initialized client context structure

The return value is a possible error

rudp_error_t rudp_client_deinit(struct rudp_client *client)  

This function is declared in rudp/client.h source file, line 213.

this function frees all internally allocated client data.

Parameters list:

  • client: An initialized and unconnected client context

The return value is a possible error

struct rudp_client_handler  

This struct is declared in rudp/client.h source file, line 87.

Client handler code callbacks

FieldDescription
void (*handle_packet)(struct rudp_client *client, int command, const void *data, size_t len) ;this struct is called on packet reception. Packet is already decoded and is ensured to be an application packet (RUDP_CMD_APP command or equivalent).
Packet chain ownership is not given to handler, handler must copy data and forget the chain afterwards.
Parameters list:
  • client: Client context
  • command: User command used
  • data: Data buffer
  • len: Useful data length
void (*link_info)(struct rudp_client *client, struct rudp_link_info *info) ;this struct is called anytime when link statistics are updated.
Parameters list:
  • client: Client context
  • info: Link quality updated information
void (*connected)(struct rudp_client *client) ;this struct is called when client gets connected. When this handler is called, client is guaranteed to have established a valid connection to the server.
Client will stay valid until rudp_client_handler::server_lost is called.
Parameters list:
  • client: Client context
void (*server_lost)(struct rudp_client *client) ;this struct is called when connection to the server drops, either explicitely or because of a timeout.
After this handler is called, client is left in the initialized state, like after rudp_client_close is called. Handler code can either use rudp_client_connect or rudp_client_deinit afterwards.
Parameters list:
  • client: Client context

rudp_error_t rudp_client_init(struct rudp_client *client, struct rudp *rudp, const struct rudp_client_handler *handler)  

This function is declared in rudp/client.h source file, line 179.

this function initializes the client context.

Parameters list:

  • client: Client unitialized context structure
  • rudp: A valid rudp context
  • handler: A client handler descriptor

The return value is a possible error

rudp_error_t rudp_client_send(struct rudp_client *client, int reliable, int command, const void *data, const size_t size)  

This function is declared in rudp/client.h source file, line 276.

this function sends data to remote server

Parameters list:

  • client: Source client
  • reliable: Whether to send the payload reliably
  • command: User command code. It may be between 0 and RUDP_CMD_APP_MAX.
  • data: Payload
  • size: Total payload size

The return value is An error level

rudp_error_t rudp_client_set_hostname(struct rudp_client *client, const char *hostname, const uint16_t port, uint32_t ip_flags)  

This function is declared in rudp/client.h source file, line 230.

this function specifies a hostname to connect to. Actual underlying address will be resolved. for details.

Parameters list:

  • client: An initialized client context structure
  • hostname: Hostname to resolve
  • port: Numeric target port (machine order)
  • ip_flags: RUDP_IPV4_ONLY, RUDP_IPV6_ONLY or RUDP_IP_ANY

The return value is a possible error

See also rudp_address_set_hostname function.

void rudp_client_set_ipv4(struct rudp_client *client, const struct in_addr *address, const uint16_t port)  

This function is declared in rudp/client.h source file, line 245.

this function specifies an IPv4 address to connect to. for details.

Parameters list:

  • client: An initialized client context structure
  • address: IPv4 to use (usual struct in_addr order)
  • port: Numeric target port (machine order)

The return value is a possible error

See also rudp_address_set_ipv4 function.

void rudp_client_set_ipv6(struct rudp_client *client, const struct in6_addr *address, const uint16_t port)  

This function is declared in rudp/client.h source file, line 260.

this function specifies an IPv6 address to connect to. for details.

Parameters list:

  • client: An initialized client context structure
  • address: IPv6 to use (usual struct in6_addr order)
  • port: Numeric target port (machine order)

The return value is a possible error

See also rudp_address_set_ipv6 function.

rudp/compiler.h header reference

Members detail  

#define RUDP_COMPILER_H_  

This macro is declared in rudp/compiler.h source file, line 13.

#define RUDP_EXPORT  

This macro is declared in rudp/compiler.h source file, line 24.

rudp/endpoint.h header reference
[Endpoint module]

Network endpoint (socket handling) More

Header inclusion  

Members  

Types  

Functions  

Description  

Endpoint is an abstration over a system socket. It handles sending and receiving of packets.

Endpoint contexts use the same life cycle as other complex objects of the library. Before use, endpoint contexts must be initialized with rudp_endpoint_init, and after use, they must be cleaned with rudp_endpoint_deinit.

Members detail  

#define RUDP_ENDPOINT_H_  

This macro is declared in rudp/endpoint.h source file, line 13.

struct rudp_endpoint  

This struct is declared in rudp/endpoint.h source file, line 76.

this struct is a endpoint context structure. User must not use its fields directly.

Endpoints are objects with the same life cycle as most other complex objects of the library. Before use, endpoint contexts must be initialized with rudp_endpoint_init, and after use, they must be cleaned with rudp_endpoint_deinit.

An initialized endpoint context can be bound with rudp_endpoint_bind to its address, and a bound endpoint context can be closed with rudp_endpoint_close. A close endpoint context stays initialized.

int rudp_endpoint_address_compare(const struct rudp_endpoint *endpoint, const struct sockaddr_storage *addr)  

This function is declared in rudp/endpoint.h source file, line 208.

this function compares the endpoint address with another address

Parameters list:

  • endpoint: Endpoint to compare address from
  • addr: Address to compare to

The return value is 0 if they match, another value otherwise

rudp_error_t rudp_endpoint_bind(struct rudp_endpoint *endpoint)  

This function is declared in rudp/endpoint.h source file, line 160.

this function open and binds an endpoint to its address

Parameters list:

  • endpoint: Endpoint to bind

void rudp_endpoint_close(struct rudp_endpoint *endpoint)  

This function is declared in rudp/endpoint.h source file, line 168.

this function closes the socket associated to this endpoint

Parameters list:

  • endpoint: Endpoint to close

void rudp_endpoint_deinit(struct rudp_endpoint *endpoint)  

This function is declared in rudp/endpoint.h source file, line 105.

this function frees all data associated to a endpoint structure

The endpoint should have no references left.

Parameters list:

  • endpoint: Endpoint structure to deinit

struct rudp_endpoint_handler  

This struct is declared in rudp/endpoint.h source file, line 42.

Endpoint handler code callbacks

FieldDescription
void (*handle_packet)(struct rudp_endpoint *endpoint, const struct sockaddr_storage *addr, struct rudp_packet_chain *packet) ;this struct is called on packet reception. Packet contains raw data.
Packet chain ownership is not given to handler, handler must copy data and forget the chain afterwards.
Parameters list:
  • endpoint: Endpoint context
  • addr: Remote address the packet was received from
  • packet: Packet descriptor structure

void rudp_endpoint_init(struct rudp_endpoint *endpoint, struct rudp *rudp, const struct rudp_endpoint_handler *handler)  

This function is declared in rudp/endpoint.h source file, line 95.

this function initializes a endpoint structure.

Parameters list:

  • endpoint: Endpoint structure to initialize
  • rudp: A valid rudp context
  • handler: A endpoint handler descriptor

rudp_error_t rudp_endpoint_recv(struct rudp_endpoint *endpoint, void *data, size_t *len, struct sockaddr_storage *addr)  

This function is declared in rudp/endpoint.h source file, line 197.

this function receives data from the associated socket.

Parameters list:

  • endpoint: Endpoint
  • data: Data buffer
  • len: (inout) On call: size avaiable in data. On return: size actually read
  • addr: (out) Peer address

The return value is a possible error, 0 if received

rudp_error_t rudp_endpoint_send(struct rudp_endpoint *endpoint, const struct rudp_address *addr, const void *data, size_t len)  

This function is declared in rudp/endpoint.h source file, line 182.

this function sends data from the endpoint to the designated remote address.

Parameters list:

  • endpoint: Enpoint to use as source
  • addr: Destination address
  • data: Data pointer
  • len: Length of data

The return value is a possible error

rudp_error_t rudp_endpoint_set_hostname(struct rudp_endpoint *endpoint, const char *hostname, const uint16_t port, uint32_t ip_flags)  

This function is declared in rudp/endpoint.h source file, line 122.

this function specifies a hostname to bind to. Actual underlying address will be resolved. for details.

Parameters list:

  • endpoint: An initialized endpoint context structure
  • hostname: Hostname to resolve
  • port: Numeric target port (machine order)
  • ip_flags: RUDP_IPV4_ONLY, RUDP_IPV6_ONLY or RUDP_IP_ANY

The return value is a possible error

See also rudp_address_set_hostname function.

void rudp_endpoint_set_ipv4(struct rudp_endpoint *endpoint, const struct in_addr *address, const uint16_t port)  

This function is declared in rudp/endpoint.h source file, line 137.

this function specifies an IPv4 address to bind to. for details.

Parameters list:

  • endpoint: An initialized endpoint context structure
  • address: IPv4 to use (usual struct in_addr order)
  • port: Numeric target port (machine order)

The return value is a possible error

See also rudp_address_set_ipv4 function.

void rudp_endpoint_set_ipv6(struct rudp_endpoint *endpoint, const struct in6_addr *address, const uint16_t port)  

This function is declared in rudp/endpoint.h source file, line 152.

this function specifies an IPv6 address to bind to. for details.

Parameters list:

  • endpoint: An initialized endpoint context structure
  • address: IPv6 to use (usual struct in6_addr order)
  • port: Numeric target port (machine order)

The return value is a possible error

See also rudp_address_set_ipv6 function.

rudp/error.h header reference
[Errors module]

Common error representation More

Header inclusion  

Members  

Type  

Description  

Error handling avoids usage of the errno C global. Error codes are directly returned from functions where relevant. They use the common rudp_error_t type. This type only means the value is an error. Error codes are taken from errno definition.

Members detail  

#define RUDP_ERROR_H_  

This macro is declared in rudp/error.h source file, line 13.

typedef int rudp_error_t  

This typedef is declared in rudp/error.h source file, line 32.

this typedef is an error code type

rudp/list.h header reference

Members detail  

#define RUDP_LIST_H_  

This macro is declared in rudp/list.h source file, line 13.

rudp/packet.h header reference
[Packet module]

Network packet structure More

Header inclusion  

Members  

Types  

Function  

Flags  

Description  

Librudp packet format is designed to support the features of the protocol. All packets contain a fixed header containing:

  • a command

  • some flags

  • a field for acking received packets sequence numbers

  • two fields for outgoing sequence numbers.

Data follows the header, in an arbitrary format. Some commands require fixed data. See relevant command definitions.

As the 1-byte command code is under-used, user can use any code equal or above RUDP_CMD_APP.

Members detail  

#define RUDP_CMD_APP_MAX  

This macro is declared in rudp/packet.h source file, line 141.

#define RUDP_OPT_ACK  

This macro is declared in rudp/packet.h source file, line 135.

Packet also contains acknoledge of received packet. ack sequence id is in reliable_ack.

#define RUDP_OPT_RELIABLE  

This macro is declared in rudp/packet.h source file, line 130.

Packet delivery is reliable. If emission fails, retransmit is performed.

#define RUDP_OPT_RETRANSMITTED  

This macro is declared in rudp/packet.h source file, line 139.

Packet was retransmitted at least once.

#define RUDP_PACKET_H_  

This macro is declared in rudp/packet.h source file, line 13.

enum rudp_command  

This enum is declared in rudp/packet.h source file, line 48.

Command definition codes

IdentifierDescription
RUDP_CMD_NOOP
Relevant field
none
Semantic
useless payload
Notes
May not be RELIABLE. Useful for keepalives (NAT, etc).
RUDP_CMD_CLOSE
Relevant field
none.
Semantic
Close the session
Expected answer
None (ACK does the job)
Notes
May be RELIABLE.
RUDP_CMD_CONN_REQ
Relevant field
conn_req.
Semantic
Expected answer
conn_rsp
Notes
Must be RELIABLE
RUDP_CMD_CONN_RSP
Relevant field
conn_rsp.
Semantic
Acknoledges CONN_REQ
Expected answer
None
Notes
Must not be RELIABLE
RUDP_CMD_PING
Relevant field
data.
Semantic
Must answer
Expected answer
PONG packet with same data
Notes
May be RELIABLE. Must not be answered for if it was retransmitted. Must still be acknoledged if reliable.
RUDP_CMD_PONG
Relevant field
data.
Semantic
PING answer
Expected answer
None
Notes
Must not be RELIABLE.
RUDP_CMD_APP
Relevant field
data
Semantic
Normal data packet
Notes
May be RELIABLE or not, if RELIABLE, must be acked. Any packet command number >= RUDP_CMD_APP is permitted

const char * rudp_command_name(enum rudp_command cmd)  

This function is declared in rudp/packet.h source file, line 219.

this function retrieves a string matching a command type. This is guaranteed to return a valid string even for undefined or user command codes.

Parameters list:

  • cmd: A command value

The return value is a command name string

struct rudp_packet  

This struct is declared in rudp/packet.h source file, line 190.

Structure factoring all the possible packet types.

struct rudp_packet_chain  

This struct is declared in rudp/packet.h source file, line 203.

Packet chain structure

FieldDescription
struct rudp_list chain_item;
struct rudp_packet *packet;
size_t alloc_size;
size_t len;

struct rudp_packet_conn_req  

This struct is declared in rudp/packet.h source file, line 161.

Connection request packet (protocol).

FieldDescription
struct rudp_packet_header header;
uint32_t data;

struct rudp_packet_conn_rsp  

This struct is declared in rudp/packet.h source file, line 170.

Connection response packet (protocol).

FieldDescription
struct rudp_packet_header header;
uint32_t accepted;

struct rudp_packet_data  

This struct is declared in rudp/packet.h source file, line 179.

Data packet (protocol).

FieldDescription
struct rudp_packet_header header;
uint8_t data[0];

struct rudp_packet_header  

This struct is declared in rudp/packet.h source file, line 149.

Packet header structure. All fields in this structure should be transmitted in network order.

FieldDescription
uint8_t command;
uint8_t opt;
uint16_t reliable_ack;
uint16_t reliable;
uint16_t unreliable;

rudp/peer.h header reference
[Peer module]

Peer implementation More

Header inclusion  

Members  

Types  

Functions  

Description  

Peer is the symmetrical implementation of the protocol. A Peer context handles the low-level protocol (with retransmits and ACKs).

Peer context does not directly handle the transport and is abstract from the network code.

Peer contexts use the same life cycle as other complex objects of the library. Before use, peer contexts must be initialized with rudp_peer_init, and after use, they must be cleaned with rudp_peer_deinit.

Either because of a connection timeout or because of relevant command is received, disconnection can happend and the rudp_peer_handler::dropped handler is called back.

Members detail  

#define RUDP_PEER_H_  

This macro is declared in rudp/peer.h source file, line 13.

struct rudp_peer  

This struct is declared in rudp/peer.h source file, line 105.

this struct is a peer context structure. User must not use its fields directly.

Peers are objects with the same life cycle as most other complex objects of the library. Before use, peer contexts must be initialized with rudp_peer_init, and after use, they must be cleaned with rudp_peer_deinit.

An initialized peer context can send packets to its peer address, and can handle incoming packets according to the protocol. It handles all the timeout and retransmit logic.

int rudp_peer_address_compare(const struct rudp_peer *peer, const struct sockaddr_storage *addr)  

This function is declared in rudp/peer.h source file, line 194.

this function compares the peer address against another address. .

Parameters list:

  • peer: Peer to compare
  • addr: Address to compare

The return value is 0 if they match, another value otherwise

See also rudp_address_compare function.

void rudp_peer_deinit(struct rudp_peer *peer)  

This function is declared in rudp/peer.h source file, line 170.

this function frees all data associated to a peer structure

Parameters list:

  • peer: Peer context to deinit

void rudp_peer_from_sockaddr(struct rudp_peer *peer, struct rudp *rudp, const struct sockaddr_storage *addr, const struct rudp_peer_handler *handler, struct rudp_endpoint *endpoint)  

This function is declared in rudp/peer.h source file, line 162.

this function initializes a peer structure knowning its remote address. This function is an alternative to calling rudp_peer_init.

Parameters list:

  • peer: Peer structure to initialize
  • rudp: A valid rudp context
  • addr: Peer's address
  • handler: A peer handler descriptor
  • endpoint: Associated endpoint to send the outgoing packets through

struct rudp_peer_handler  

This struct is declared in rudp/peer.h source file, line 52.

Peer handler code callbacks

FieldDescription
void (*handle_packet)(struct rudp_peer *peer, struct rudp_packet_chain *packet) ;this struct is called on packet reception. Packet is already decoded and is ensured to be an application packet (RUDP_CMD_APP command or equivalent).
Packet chain ownership is not given to handler, handler must copy data and forget the chain afterwards.
Parameters list:
  • peer: Peer context
  • packet: Packet descriptor structure
void (*link_info)(struct rudp_peer *peer, struct rudp_link_info *info) ;this struct is called anytime when link statistics are updated.
Parameters list:
  • peer: Peer context
  • info: Link quality updated information
void (*dropped)(struct rudp_peer *peer) ;this struct is called when connection to the peer drops, either explicitely or because of a timeout.
After this handler is called, peer is left in the initialized state. Handler code can either resend packets (which will use reset sequence numbers) or call rudp_peer_deinit.
Parameters list:
  • peer: Peer context

rudp_error_t rudp_peer_incoming_packet(struct rudp_peer *peer, struct rudp_packet_chain *pc)  

This function is declared in rudp/peer.h source file, line 206.

this function passes an incoming packet to the peer handler code.

Parameters list:

  • peer: Peer context
  • pc: Packet descriptor structure

The return value is a possible error value

void rudp_peer_init(struct rudp_peer *peer, struct rudp *rudp, const struct rudp_peer_handler *handler, struct rudp_endpoint *endpoint)  

This function is declared in rudp/peer.h source file, line 142.

this function initializes a peer structure.

Parameters list:

  • peer: Peer structure to initialize
  • rudp: A valid rudp context
  • handler: A peer handler descriptor
  • endpoint: Associated endpoint to send the outgoing packets through

void rudp_peer_reset(struct rudp_peer *peer)  

This function is declared in rudp/peer.h source file, line 182.

this function resets a peer context.

This resets sequence numbers, state, timers and send queue. Resetting a peer can be useful on lost connection, in order to start over.

Parameters list:

  • peer: Peer context to reset

rudp_error_t rudp_peer_send_close_noqueue(struct rudp_peer *peer)  

This function is declared in rudp/peer.h source file, line 255.

this function immediately sends an unreliable RUDP_CMD_CLOSE command, bypassing the current retransmit queue.

Parameters list:

  • peer: Destination peer

rudp_error_t rudp_peer_send_connect(struct rudp_peer *peer)  

This function is declared in rudp/peer.h source file, line 246.

this function sends a reliable connect packet to a peer.

Parameters list:

  • peer: Destination peer

rudp_error_t rudp_peer_send_reliable(struct rudp_peer *peer, struct rudp_packet_chain *pc)  

This function is declared in rudp/peer.h source file, line 238.

this function sends reliable data to a peer.

Calling code doesn't have to initialize the packet header.

Parameters list:

  • peer: Destination peer
  • pc: Packet chain element

Peer handling code becomes owner of the pc pointer, and may free it when needed.

rudp_error_t rudp_peer_send_unreliable(struct rudp_peer *peer, struct rudp_packet_chain *pc)  

This function is declared in rudp/peer.h source file, line 222.

this function sends unreliable data to a peer.

Calling code doesn't have to initialize the packet header.

Parameters list:

  • peer: Destination peer
  • pc: Packet chain element

Peer handling code becomes owner of the pc pointer, and may free it when needed.

rudp/rudp.h header reference
[Master state module]

Master library state More

Header inclusion  

Members  

Types  

Functions  

  • void rudp_deinit(struct rudp *rudp)
  • rudp_error_t rudp_init(struct rudp *rudp, struct ela_el *el, const struct rudp_handler *handler)
  • uint16_t rudp_random(struct rudp *rudp)

Constant  

Macro  

Description  

Master library state holds context used for administrative purposes of the library. It handles:

  • Event loop abstraction handling (though libela)

  • Memory management

  • Logging

Master library state must be passed to all library objects initialization.

A libela context must be initialized before the rudp context. See libela documentation for more information.

When a handler is defined for logging, it gets all the messages from the library. If user wants to filter messages, it can use the level parameter. .

Memory allocation is handler through alloc/free-like functions. for functions to implement.

Librudp provides sane defaults for the needed handlers, not reporting any log messages, and using malloc and free from the system's libc. Such handler is defined as RUDP_HANDLER_DEFAULT.

Sample usage:

struct rudp rudp;
struct ela_el *el = ...;

rudp_init(&rudp, el, RUDP_HANDLER_DEFAULT);

// allocate and initialize some objects

// run your event loop

// deinitialize and free the objects

rudp_deinit(&rudp);

Members detail  

#define RUDP_HANDLER_DEFAULT  

This macro is declared in rudp/rudp.h source file, line 132.

Can be used where default allocators and no logging output is needed for rudp_init.

#define RUDP_RUDP_H_  

This macro is declared in rudp/rudp.h source file, line 13.

struct rudp  

This struct is declared in rudp/rudp.h source file, line 146.

this struct is a rudp context

Rudp have the same life cycle as most other complex objects of the library. Before use, rudp contexts must be initialized with rudp_init, and after use, they must be cleaned with rudp_deinit.

void rudp_deinit(struct rudp *rudp)  

This function is declared in rudp/rudp.h source file, line 177.

this function initializes a master library state structure

Parameters list:

  • rudp: Rudp context to deinitialize

struct rudp_handler  

This struct is declared in rudp/rudp.h source file, line 91.

Master state handler code callbacks

FieldDescription
void (*log)(struct rudp *rudp, enum rudp_log_level level, const char *fmt, va_list arg) ;this struct can be called anytime in the state life, to gather information about the library actions.
Setting NULL in this callback is permitted to get no messages at all.
Parameters list:
  • rudp: The rudp context
  • level: Log level of the message
  • fmt: Message printf-like format
  • arg: Argument list
void *(*mem_alloc)(struct rudp *rudp, size_t size) ;this struct is called each time the library needs memory.
Parameters list:
  • rudp: The rudp context
  • size: Size of buffer needed
The return value is A newly allocated buffer, or NULL
void (*mem_free)(struct rudp *rudp, void *buffer) ;this struct is called each time the library frees a previously allocated buffer.
Parameters list:
  • rudp: The rudp context
  • buffer: Previously allocated buffer to release

const struct rudp_handler rudp_handler_default  

This variable is declared in rudp/rudp.h source file, line 127.

rudp_error_t rudp_init(struct rudp *rudp, struct ela_el *el, const struct rudp_handler *handler)  

This function is declared in rudp/rudp.h source file, line 169.

this function initializes a master library state structure

Parameters list:

  • rudp: Rudp context to initialize
  • el: A valid event loop abstraction context
  • handler: A rudp handler descriptor. Use RUDP_HANDLER_DEFAULT if no specific behavior is intended.

The return value is a possible error

enum rudp_log_level  

This enum is declared in rudp/rudp.h source file, line 77.

this enum defines log levels of log messages.

IdentifierDescription
RUDP_LOG_IO
RUDP_LOG_DEBUG
RUDP_LOG_INFO
RUDP_LOG_WARN
RUDP_LOG_ERROR

uint16_t rudp_random(struct rudp *rudp)  

This function is declared in rudp/rudp.h source file, line 185.

this function generates a 16 bit random value

Parameters list:

  • rudp: Rudp context to deinitialize

rudp/server.h header reference
[Server module]

Server implementation More

Header inclusion  

Members  

Types  

Functions  

Description  

Server binds to a given socket address and waits for clients to connect. For binding, It either uses an explicit constant IPv4 or IPv6 address, or an hostname to resolve.

When a client connects, as long as the connection is established, data can be exchanged both ways, either reliably or not. User code gets notified of clients (un)connecting.

Server contexts use the same life cycle as other complex objects of the library. Before use, server contexts must be initialized with rudp_server_init, and after use, they must be cleaned with rudp_server_deinit.

An initialized but not yet bound Server context must have its server address setup with any of the following functions: rudp_server_set_hostname, rudp_server_set_ipv4 or rudp_server_set_ipv6.

Once the server address is setup properly, Server context can be bound with rudp_server_bind. After successful binding, the server waits for clients and data packets.

User code may store an user-handled user data pointer inside the peer structures associated to a server context. This can be done through the rudp_server_peer_data_set and rudp_server_peer_data_get functions.

Sample usage:

// assuming you have a valid rudp context here:
struct rudp *rudp;

struct rudp_server server;

rudp_server_init(&server, rudp, &my_server_handlers);

// set the address and bind
rudp_server_set_ipv4(&server, ...);
rudp_server_bind(&server);

// run your event loop

rudp_server_close(&server);
rudp_server_deinit(&server);

Members detail  

#define RUDP_SERVER_H_  

This macro is declared in rudp/server.h source file, line 13.

struct rudp_server  

This struct is declared in rudp/server.h source file, line 162.

this struct is a server context structure. User should not use its fields directly.

Servers are objects with the same life cycle as most other complex objects of the library. Before use, server contexts must be initialized with rudp_server_init, and after use, they must be cleaned with rudp_server_deinit.

An initialized server context can be bound with rudp_server_bind to a port, and a bound server context can be closed with rudp_server_close. A closed server context stays initialized.

rudp_error_t rudp_server_bind(struct rudp_server *server)  

This function is declared in rudp/server.h source file, line 197.

this function binds the server context to an address. This both creates a socket and binds it to the relevant address/port set with any of the rudp_server_set_hostname, rudp_server_set_ipv4 or rudp_server_set_ipv6.

Parameters list:

  • server: An initialized server context structure

The return value is a possible error

void rudp_server_client_close(struct rudp_server *server, struct rudp_peer *peer)  

This function is declared in rudp/server.h source file, line 342.

this function cleanly drops connection to one client.

Parameters list:

  • server: Source server
  • peer: Destination peer corresponding to client

rudp_error_t rudp_server_close(struct rudp_server *server)  

This function is declared in rudp/server.h source file, line 210.

this function unbinds the server context from an address, closes all associated sockets and drops all peers. A rudp_server_handler::peer_dropped handler will be called for each present peer.

Parameters list:

  • server: A bound server context structure

The return value is a possible error

rudp_error_t rudp_server_deinit(struct rudp_server *server)  

This function is declared in rudp/server.h source file, line 220.

this function frees all internally allocated server data.

Parameters list:

  • server: An initialized and unbound server context

The return value is a possible error

struct rudp_server_handler  

This struct is declared in rudp/server.h source file, line 84.

Server handler code callbacks

FieldDescription
void (*handle_packet)(struct rudp_server *server, struct rudp_peer *peer, int command, const void *data, size_t len) ;this struct is called on packet reception. Packet is already decoded and is ensured to be an application packet (RUDP_CMD_APP command or equivalent).
Packet chain ownership is not given to handler, handler must copy data and forget the chain afterwards.
Parameters list:
  • server: Server context
  • peer: Relevant peer
  • command: User command used
  • data: Data buffer
  • len: Useful data length
void (*link_info)(struct rudp_server *server, struct rudp_peer *peer, struct rudp_link_info *info) ;this struct is called anytime when link statistics are updated.
Parameters list:
  • server: Server context
  • peer: Relevant peer
  • info: Link quality updated information
void (*peer_dropped)(struct rudp_server *server, struct rudp_peer *peer) ;this struct is called when a peer drops, either explicitely or because of a timeout.
After this handler is called, handler code must forget its references to the peer. The peer structure is not valid afterwards.
Parameters list:
  • server: Server context
  • peer: Relevant peer
void (*peer_new)(struct rudp_server *server, struct rudp_peer *peer) ;this struct is called when a new peer gets connected. When this handler is called, peer is guaranteed to have established a valid connection.
Handler code may retain pointer references to peer, and may even store user data pointer inside it.
Peer will stay valid until rudp_server_handler::peer_dropped is called.
Parameters list:
  • server: Server context
  • peer: New peer

rudp_error_t rudp_server_init(struct rudp_server *server, struct rudp *rudp, const struct rudp_server_handler *handler)  

This function is declared in rudp/server.h source file, line 184.

this function initializes the server context.

Parameters list:

  • server: Server unitialized context structure
  • rudp: A valid rudp context
  • handler: A server handler descriptor

The return value is a possible error

void * rudp_server_peer_data_get(struct rudp_server *server, struct rudp_peer *peer)  

This function is declared in rudp/server.h source file, line 317.

this function retrieves user code private data pointer associated to a peer.

Parameters list:

  • server: Server context this peer belongs to
  • peer: Peer context pointer is associated to

The return value is the latest user pointer set for this peer (NULL if never set before)

void rudp_server_peer_data_set(struct rudp_server *server, struct rudp_peer *peer, void *data)  

This function is declared in rudp/server.h source file, line 330.

this function sets user code private data pointer associated to a peer.

Parameters list:

  • server: Server context this peer belongs to
  • peer: Peer context to associate the pointer to
  • data: User pointer

rudp_error_t rudp_server_send(struct rudp_server *server, struct rudp_peer *peer, int reliable, int command, const void *data, const size_t size)  

This function is declared in rudp/server.h source file, line 286.

this function sends data from this server to a peer.

Parameters list:

  • server: Source server
  • peer: Destination peer
  • reliable: Whether to send the payload reliably
  • command: User command code. It may be between 0 and RUDP_CMD_APP_MAX.
  • data: Payload
  • size: Total packet size

The return value is An error level

rudp_error_t rudp_server_send_all(struct rudp_server *server, int reliable, int command, const void *data, const size_t size)  

This function is declared in rudp/server.h source file, line 303.

this function sends data from this server to all peers.

Parameters list:

  • server: Source server
  • reliable: Whether to send the payload reliably
  • command: User command code. It may be between 0 and RUDP_CMD_APP_MAX.
  • data: Payload
  • size: Total packet size

The return value is An error level

rudp_error_t rudp_server_set_hostname(struct rudp_server *server, const char *hostname, const uint16_t port, uint32_t ip_flags)  

This function is declared in rudp/server.h source file, line 237.

this function specifies a hostname to bind to. Actual underlying address will be resolved. for details.

Parameters list:

  • server: An initialized server context structure
  • hostname: Hostname to resolve
  • port: Numeric target port (machine order)
  • ip_flags: RUDP_IPV4_ONLY, RUDP_IPV6_ONLY or RUDP_IP_ANY

The return value is a possible error

See also rudp_address_set_hostname function.

void rudp_server_set_ipv4(struct rudp_server *server, const struct in_addr *address, const uint16_t port)  

This function is declared in rudp/server.h source file, line 252.

this function specifies an IPv4 address to bind to. for details.

Parameters list:

  • server: An initialized server context structure
  • address: IPv4 to use (usual struct in_addr order)
  • port: Numeric target port (machine order)

The return value is a possible error

See also rudp_address_set_ipv4 function.

void rudp_server_set_ipv6(struct rudp_server *server, const struct in6_addr *address, const uint16_t port)  

This function is declared in rudp/server.h source file, line 267.

this function specifies an IPv6 address to bind to. for details.

Parameters list:

  • server: An initialized server context structure
  • address: IPv6 to use (usual struct in6_addr order)
  • port: Numeric target port (machine order)

The return value is a possible error

See also rudp_address_set_ipv6 function.

rudp/time.h header reference
[Time module]

Uniform time representation More

Members  

Type  

Functions  

Description  

Time handling is done through the rudp_time_t type. This type is a scalar and can be manipulated with usual scalar operations.

The only functions declared for usage with rudp_time_t are rudp_timestamp and rudp_timestamp_to_timeval.

Members detail  

#define RUDP_TIME_H_  

This macro is declared in rudp/time.h source file, line 13.

#define RUDP_TIME_MAX  

This macro is declared in rudp/time.h source file, line 36.

typedef int64_t rudp_time_t  

This typedef is declared in rudp/time.h source file, line 35.

this typedef is an abstract time type definition. It contains miliseconds since a common time reference.

rudp_time_t rudp_timestamp(void )  

This function is declared in rudp/time.h source file, line 46.

this function retrieves the current library timestamp

The return value is a timestamp

void rudp_timestamp_to_timeval(struct timeval *tv, rudp_time_t ts)  

This function is declared in rudp/time.h source file, line 60.

this function converts a milisecond value to a struct timeval.

Parameters list:

  • tv: (out) Timeval structure
  • ts: Timestamp

All declarations  

Members  

Types  

Functions  

Constant  

Macro  

Flags  

Valid XHTML 1.0 StrictGenerated by nipo on Tue Oct 11 17:45:49 2011 using MkDoc