reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
net_util.h
Go to the documentation of this file.
1
38#ifndef NET_UTIL_H
39#define NET_UTIL_H
40
41#ifdef PLATFORM_ARDUINO
42#error To be implemented. No support for federation on Arduino yet.
43#else
44#include <sys/socket.h>
45#include <regex.h>
46#endif
47
48#include <sys/types.h>
49#include <stdbool.h>
50
51#include "low_level_platform.h"
52#include "tag.h"
53
54#define NUM_SOCKET_RETRIES 10
55#define DELAY_BETWEEN_SOCKET_RETRIES MSEC(100)
56
57#define HOST_LITTLE_ENDIAN 1
58#define HOST_BIG_ENDIAN 2
59
64int host_is_big_endian(void);
65
66#ifdef FEDERATED
67
71extern lf_mutex_t socket_mutex;
72
80int create_real_time_tcp_socket_errexit();
81
96int read_from_socket(int socket, size_t num_bytes, unsigned char* buffer);
97
107int read_from_socket_close_on_error(int* socket, size_t num_bytes, unsigned char* buffer);
108
125void read_from_socket_fail_on_error(int* socket, size_t num_bytes, unsigned char* buffer, lf_mutex_t* mutex,
126 char* format, ...);
127
136ssize_t peek_from_socket(int socket, unsigned char* result);
137
152int write_to_socket(int socket, size_t num_bytes, unsigned char* buffer);
153
163int write_to_socket_close_on_error(int* socket, size_t num_bytes, unsigned char* buffer);
164
180void write_to_socket_fail_on_error(int* socket, size_t num_bytes, unsigned char* buffer, lf_mutex_t* mutex,
181 char* format, ...);
182
183#endif // FEDERATED
184
192void encode_int64(int64_t data, unsigned char* buffer);
193
201void encode_int32(int32_t data, unsigned char* buffer);
202
210void encode_uint32(uint32_t data, unsigned char* buffer);
211
219void encode_uint16(uint16_t data, unsigned char* buffer);
220
232int32_t swap_bytes_if_big_endian_int32(int32_t src);
233
245int64_t swap_bytes_if_big_endian_int64(int64_t src);
246
258uint16_t swap_bytes_if_big_endian_uint16(uint16_t src);
259
264int32_t extract_int32(unsigned char* bytes);
265
270int64_t extract_int64(unsigned char* bytes);
271
277uint16_t extract_uint16(unsigned char* bytes);
278
279#ifdef FEDERATED
280
291void extract_header(unsigned char* buffer, uint16_t* port_id, uint16_t* federate_id, size_t* length);
292
305void extract_timed_header(unsigned char* buffer, uint16_t* port_id, uint16_t* federate_id, size_t* length, tag_t* tag);
306
316tag_t extract_tag(unsigned char* buffer);
317
326void encode_tag(unsigned char* buffer, tag_t tag);
327
331typedef struct rti_addr_info_t {
332 char rti_host_str[256];
333 char rti_port_str[6];
334 char rti_user_str[256];
335 bool has_host;
336 bool has_port;
337 bool has_user;
338} rti_addr_info_t;
339
344bool match_regex(const char* str, char* regex);
345
350bool validate_port(char* port);
351
356bool validate_host(const char* host);
357
362bool validate_user(const char* user);
363
368bool extract_match_group(const char* rti_addr, char* dest, regmatch_t group, size_t max_len, size_t min_len,
369 const char* err_msg);
370
375bool extract_match_groups(const char* rti_addr, char** rti_addr_strs, bool** rti_addr_flags, regmatch_t* group_array,
376 int* gids, size_t* max_lens, size_t* min_lens, const char** err_msgs);
377
381void extract_rti_addr_info(const char* rti_addr, rti_addr_info_t* rti_addr_info);
382
383#endif // FEDERATED
384
385#endif /* NET_UTIL_H */
void * lf_mutex_t
Definition lf_arduino_support.h:118
Platform API support for the C target of Lingua Franca.
uint16_t extract_uint16(unsigned char *bytes)
Definition net_util.c:398
uint16_t swap_bytes_if_big_endian_uint16(uint16_t src)
Definition net_util.c:349
int64_t extract_int64(unsigned char *bytes)
Definition net_util.c:388
int32_t extract_int32(unsigned char *bytes)
Definition net_util.c:368
void encode_uint32(uint32_t data, unsigned char *buffer)
Definition net_util.c:247
int64_t swap_bytes_if_big_endian_int64(int64_t src)
Definition net_util.c:321
int host_is_big_endian(void)
Definition net_util.c:263
void encode_int64(int64_t data, unsigned char *buffer)
Definition net_util.c:228
int32_t swap_bytes_if_big_endian_int32(int32_t src)
Definition net_util.c:277
void encode_uint16(uint16_t data, unsigned char *buffer)
Definition net_util.c:256
void encode_int32(int32_t data, unsigned char *buffer)
Definition net_util.c:238
Definition tag.h:78
Time and tag definitions and functions for Lingua Franca.
char buffer[BUFFER_SIZE]
Definition trace_util.c:42