31 #include <sys/epoll.h>
34 #define MAX_RUNTIME_FD 1024
46 log_error(
"Runtime socket already initialized to %d. Cannot reinitialize",
52 log_error(
"Error initializing runtime socket on port %d", port);
55 log_info(
"Initialized runtime socket on port %d", port);
60 log_error(
"Error initializing runtime epoll. Closing runtime socket.");
91 log_error(
"Cannot accept runtime connection on file descriptor greater than %d",
103 log_error(
"Runtime socket or epoll not initialized. Cannot start monitor loop");
110 log_error(
"Epoll loop exited with error");
118 log_error(
"Epoll not initialized. Cannot monitor new socket");
124 log_perror(
"Error adding socket %d to epoll", new_fd);
132 log_error(
"Epoll not initialized. Cannot monitor new socket");
139 log_perror(
"Error adding socket %d to epoll", new_fd);
154 log_info(
"Attempting to connect to controller");
160 log_info(
"Connected to global controller on socket %d. Entering socket monitor loop.", sock);
Interface for general-purpose socket communication.
#define log_info(fmt,...)
Socket-handling between runtimes.
Wrapper functions for epoll to manage event-based communication.
int monitor_runtime_socket(int new_fd)
Adds a runtime to be monitored by the socket monitor.
int epoll_fd
The epoll file descriptor monitoring sockets.
#define log_critical(fmt,...)
#define log_perror(fmt,...)
Logging of status messages to the terminal.
int init_controller_socket(struct sockaddr_in *addr)
Initilizes a connection with the global controller located at the provided address.
int handle_runtime_communication(int fd)
Reads a message off of the provided file descriptor as if it is coming from a runtime peer...
int add_to_epoll(int epoll_fd, int new_fd, uint32_t events, bool oneshot)
Adds a file descriptor to an epoll instance.
int init_epoll(int socket_fd)
Initializes a new instance of an epoll file descriptor and adds a socket to it, listening for input o...
#define log_error(fmt,...)
int monitor_controller_socket(int new_fd)
Adds the global controller to be monitored by the socket monitor.
int runtime_socket
The socket on which incoming connections are monitored.
int epoll_loop(int socket_fd, int epoll_fd, int batch_size, int timeout, bool oneshot, int(*connection_handler)(int, void *), int(*accept_handler)(int, void *), void *data)
The event-based loop for epoll_wait.
static bool runtime_fds[1024]
Whether the file descriptor has been associated with a runtime.
static int accept_connection(int fd, void *data)
Accepts a new connection.
int init_runtime_socket(int listen_port)
Initializes the socket listening for incoming connections.
static int init_socket_monitor(int port)
Initializes the socket monitor on the given port.
static int handle_connection(int fd, void *data)
Checks if the file descriptor is a runtime or controller, and handles it appropraitely.
int run_socket_monitor(int local_port, struct sockaddr_in *ctrl_addr)
Starts (blocking) the socket monitor, listening on the provided port.
int handle_controller_communication(int fd)
Reads and processes a controller message off of the provided file descriptor.
#define MAX_RUNTIME_FD
The maximum file descriptor that can be associated with a runtime.
static int socket_monitor_epoll_loop()
The main loop for the socket monitor.
Communication with global controller from runtime.