reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
socket_common.h File Reference

Common socket operations and utilities for federated Lingua Franca programs. More...

Go to the source code of this file.

Macros

#define CONNECT_RETRY_INTERVAL   MSEC(500)
 Time between a federate's attempts to connect to the RTI.
#define CONNECT_TIMEOUT   MINUTES(1)
 Bound on the number of retries to connect to the RTI.
#define DEFAULT_PORT   15045u
 Default port number for the RTI.
#define DELAY_BETWEEN_SOCKET_RETRIES   MSEC(100)
 The amount of time to wait after a failed socket read or write before trying again.
#define MAX_NUM_PORT_ADDRESSES   16u
 Maximum number of port addresses that a federate will try to connect to the RTI on.
#define MSG_TYPE_FAILED   25
 Byte identifying that the federate or the RTI has failed.
#define NUMBER_OF_FEDERATES   1
 The number of federates.
#define PORT_BIND_RETRY_INTERVAL   SEC(1)
 Time to wait before re-attempting to bind to a port.
#define PORT_BIND_RETRY_LIMIT   60
 Number of attempts to bind to a port before giving up.
#define TCP_TIMEOUT_TIME   SEC(10)
 The timeout time in ns for TCP operations.
#define UDP_TIMEOUT_TIME   SEC(1)
 The timeout time in ns for UDP operations.

Typedefs

typedef enum socket_type_t socket_type_t
 Type of socket.

Enumerations

enum  socket_type_t { TCP , UDP }
 Type of socket. More...

Functions

int accept_socket (int socket, int rti_socket)
 Wait for an incoming connection request on the specified server socket.
int connect_to_socket (int sock, const char *hostname, int port)
 Attempt to establish a TCP connection to the specified hostname and port.
int create_real_time_tcp_socket_errexit ()
 Create an IPv4 TCP socket with Nagle's algorithm disabled.
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.
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 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.
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.
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 if an error occurs.
int shutdown_socket (int *socket, bool read_before_closing)
 Shutdown and close the 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.
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.

Detailed Description

Common socket operations and utilities for federated Lingua Franca programs.

Author
Edward A. Lee
Soroush Bateni
Peter Donovan

This file provides common socket operations and utilities used in federated Lingua Franca programs. It includes functions for creating and managing TCP/UDP sockets, handling connections, and performing read/write operations with proper error handling and retry mechanisms. The file also defines various constants for timeouts, retry intervals, and port configurations.