reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
socket_common.h
Go to the documentation of this file.
1
15#ifndef SOCKET_COMMON_H
16#define SOCKET_COMMON_H
17
18#include "low_level_platform.h"
19
26#ifndef NUMBER_OF_FEDERATES
27#define NUMBER_OF_FEDERATES 1
28#endif
29
36#define DELAY_BETWEEN_SOCKET_RETRIES MSEC(100)
37
44#define TCP_TIMEOUT_TIME SEC(10)
45
52#define UDP_TIMEOUT_TIME SEC(1)
53
58#define CONNECT_RETRY_INTERVAL MSEC(500)
59
67#define CONNECT_TIMEOUT MINUTES(1)
68
76#define MAX_NUM_PORT_ADDRESSES 16u
77
87#define PORT_BIND_RETRY_INTERVAL SEC(1)
88
93#define PORT_BIND_RETRY_LIMIT 60
94
103#define DEFAULT_PORT 15045u
104
109#define MSG_TYPE_FAILED 25
110
116
127
149int create_server(uint16_t port, int* final_socket, uint16_t* final_port, socket_type_t sock_type,
150 bool increment_port_on_retry);
151
170
171int accept_socket(int socket, int rti_socket);
172
188int connect_to_socket(int sock, const char* hostname, int port);
189
206int read_from_socket(int socket, size_t num_bytes, unsigned char* buffer);
207
219int read_from_socket_close_on_error(int* socket, size_t num_bytes, unsigned char* buffer);
220
238void read_from_socket_fail_on_error(int* socket, size_t num_bytes, unsigned char* buffer, char* format, ...);
239
250ssize_t peek_from_socket(int socket, unsigned char* result);
251
268int write_to_socket(int socket, size_t num_bytes, unsigned char* buffer);
269
282int write_to_socket_close_on_error(int* socket, size_t num_bytes, unsigned char* buffer);
283
302void write_to_socket_fail_on_error(int* socket, size_t num_bytes, unsigned char* buffer, lf_mutex_t* mutex,
303 char* format, ...);
304
312
328int shutdown_socket(int* socket, bool read_before_closing);
329
330#endif /* SOCKET_COMMON_H */
int create_real_time_tcp_socket_errexit()
Create an IPv4 TCP socket with Nagle's algorithm disabled.
int shutdown_socket(int *socket, bool read_before_closing)
Shutdown and close the socket.
int accept_socket(int socket, int rti_socket)
Wait for an incoming connection request on the specified server socket.
void read_from_socket_fail_on_error(int *socket, size_t num_bytes, unsigned char *buffer, char *format,...)
Read the specified number of bytes from the specified socket into the specified buffer and close the ...
socket_type_t
Type of socket.
Definition socket_common.h:115
int connect_to_socket(int sock, const char *hostname, int port)
Attempt to establish a TCP connection to the specified hostname and port.
int read_from_socket_close_on_error(int *socket, size_t num_bytes, unsigned char *buffer)
Read the specified number of bytes from the specified socket into the specified buffer.
int create_server(uint16_t port, int *final_socket, uint16_t *final_port, socket_type_t sock_type, bool increment_port_on_retry)
Create a TCP server that listens for socket connections.
int read_from_socket(int socket, size_t num_bytes, unsigned char *buffer)
Read the specified number of bytes from the specified socket into the specified buffer.
void write_to_socket_fail_on_error(int *socket, size_t num_bytes, unsigned char *buffer, lf_mutex_t *mutex, char *format,...)
Write the specified number of bytes to the specified socket.
void init_shutdown_mutex(void)
Initialize shutdown mutex.
ssize_t peek_from_socket(int socket, unsigned char *result)
Without blocking, peek at the specified socket.
int write_to_socket(int socket, size_t num_bytes, unsigned char *buffer)
Write the specified number of bytes to the specified socket from the specified buffer.
int write_to_socket_close_on_error(int *socket, size_t num_bytes, unsigned char *buffer)
Write the specified number of bytes to the specified socket.
@ TCP
Definition socket_common.h:115
@ UDP
Definition socket_common.h:115
Platform API support for the C target of Lingua Franca.