36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/tcp.h>
56 #define MAX_RUNTIME_ID 32
66 log_error(
"Requested peer %d is greater than max runtime ID %d",
72 log_error(
"Requested peer %d not instantiated", runtime_id);
78 log_error(
"Error sending header to runtime %d", runtime_id);
88 log_error(
"Error sending payload to runtime %d", runtime_id);
91 log(LOG_RUNTIME_COMMUNICATION,
"Send a payload of size %d (type %d) to runtime %d (fd: %d)",
99 if (fstat(fd, &buf) != 0) {
100 log_error(
"Cannot register non-descriptor %d for runtime ID %d", fd, runtime_id);
104 log_error(
"Runtime ID %d too high!", runtime_id);
108 log_warn(
"Replacing runtime peer with id %d", runtime_id);
113 int rtn = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val,
sizeof(val));
118 log_info(
"Added runtime peer %d (fd: %d)", runtime_id, fd);
128 log_error(
"Could not send local runtime ID to remote runtime %d",
id);
139 .payload_size =
sizeof(msg)
144 log_error(
"Could not send initial connection message to peer runtime %d",
id);
152 log_warn(
"Attempting to replace runtime peer with id %d",
id);
156 log_error(
"Could not connect to runtime %u",
id);
162 int rtn = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val,
sizeof(val));
168 log_error(
"Failed to send initialization message to runtime %d (fd: %d)",
id, fd);
173 log_info(
"Connected to runtime peer %d (fd: %d)",
id, fd);
179 log_error(
"Runtime socket already initialized");
184 log_error(
"Error initializing runtime socket");
195 log_error(
"Could not read runtime message header from socket %d", fd);
208 log_error(
"Error getting MSU with ID %d, requested from runtime fd %d",
211 void *unused = malloc(payload_size);
217 log(LOG_RUNTIME_CONNECTION,
"Attempting to read MSU message");
219 if (msu_msg == NULL) {
220 log_error(
"Error reading MSU msg off of fd %d", fd);
226 log_error(
"Error enqueuing inter-msu message to MSU %d from runtime fd %d",
240 log_warn(
"Payload size of runtime initialization message does not match init_msg");
244 log_error(
"Error reading inter_runtime_init_message from fd %d", fd);
253 log(LOG_RUNTIME_COMMUNICATION,
"Runtime peer %d (fd: %d) added",
268 log_error(
"Error processing forward message from fd %d", fd);
275 log_error(
"Error processing init runtime message from fd %d", fd);
280 log_error(
"Received unknown message type from fd %d: %d", fd, hdr->
type);
291 log_error(
"Error reading runtime message");
295 log(LOG_INTER_RUNTIME_COMMUNICATION,
296 "Read message from runtime with fd %d", fd);
301 log_error(
"Error processing inter-runtime message from fd %d", fd);
int init_connected_socket(struct sockaddr_in *addr)
Initializes a socket that is connected to a given address.
Interface for general-purpose socket communication.
Collecting statistics within the runtime.
static int process_fwd_to_msu_message(size_t payload_size, int msu_id, int fd)
Sent to a newly-connected runtime to establish ID.
static struct runtime_peer runtime_peers[32]
Other runtime peer sockets.
static int process_init_rt_message(size_t payload_size, int fd)
Processes an init message which has just been received from another runtime.
Messages to be delivered to dedos_threads.
#define log_info(fmt,...)
Socket-handling between runtimes.
int monitor_runtime_socket(int new_fd)
Adds a runtime to be monitored by the socket monitor.
Header for messages to runtime from another runtime.
int read_payload(int fd, size_t size, void *buff)
Reads a buffer of a given size from a file descriptor.
int send_to_peer(unsigned int runtime_id, struct inter_runtime_msg_hdr *hdr, void *payload)
Sends a message to the peer runtime with the provided id.
struct msu_msg * read_msu_msg(struct local_msu *msu, int fd, size_t size)
Reads an MSU message of the given size from the provided file descriptor.
Monitors an incoming port for messages from runtime or controller.
int add_runtime_peer(unsigned int runtime_id, int fd)
Adds the file descriptor to the list of current runtime peers.
#define log_perror(fmt,...)
Logging of status messages to the terminal.
Interactions with global dfg from individual runtime.
int handle_runtime_communication(int fd)
Reads a message off of the provided file descriptor as if it is coming from a runtime peer...
void destroy_msu_msg_and_contents(struct msu_msg *msg)
Frees both the message and message data.
Payload type: inter_runtime_init_msg.
#define log_error(fmt,...)
Declares the structures and functions applicable to MSUs on the local machine.
struct local_msu * get_local_msu(unsigned int id)
Gets the local MSU with the given ID, or NULL if N/A.
Paylaod type: output of serialize_msu_msg.
The structure that represents an MSU located on the local machine.
unsigned int target
MSU ID or thread ID depending on message type.
struct msg_queue queue
Input queue to MSU.
static int read_runtime_message_hdr(int fd, struct inter_runtime_msg_hdr *msg)
Reads a header from a peer runtime.
static int process_runtime_message_hdr(struct inter_runtime_msg_hdr *hdr, int fd)
Processes the header which has been received on fd, and processes the header's payload.
Definitions of the message types that can be passed between runtimes.
Holds the file descriptor for a single runtime peer.
int connect_to_runtime_peer(unsigned int id, struct sockaddr_in *addr)
Innitiates a connection to a runtime peer with the given ID at the given address. ...
int init_runtime_socket(int listen_port)
Initializes the socket listening for incoming connections.
unsigned int origin_id
ID of the sending runtime.
static int runtime_sock
Static (global) variable for the socket listening for other runtimes.
int init_listening_socket(int port)
Initializes a socket which is bound to and listening on the given port.
static int runtime_id(int runtime_fd)
#define MAX_RUNTIME_ID
Maximum number of other runtimes that can connect to this one.
#define log(level, fmt,...)
Log at a custom level.
A message that is to be delivered to an instance of an MSU.
ssize_t send_to_endpoint(int fd, void *data, size_t data_len)
Writes a buffer of a given size to a file descriptor.
static int send_init_msg(int id)
Sends the inter_runtime_init message to the runtime with the given ID.
enum inter_runtime_msg_type type
int enqueue_msu_msg(struct msg_queue *q, struct msu_msg *data)
Enqueues a message for immediate delivery.
#define log_warn(fmt,...)