My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
socket_monitor.c File Reference

Monitors an incoming port for messages from runtime or controller. More...

#include "epollops.h"
#include "communication.h"
#include "logging.h"
#include "controller_communication.h"
#include "runtime_communication.h"
#include <sys/epoll.h>

Go to the source code of this file.

Macros

#define MAX_RUNTIME_FD   1024
 The maximum file descriptor that can be associated with a runtime. More...
 

Functions

static int init_socket_monitor (int port)
 Initializes the socket monitor on the given port. More...
 
static int handle_connection (int fd, void *data)
 Checks if the file descriptor is a runtime or controller, and handles it appropraitely. More...
 
static int accept_connection (int fd, void *data)
 Accepts a new connection. More...
 
static int socket_monitor_epoll_loop ()
 The main loop for the socket monitor. More...
 
int monitor_controller_socket (int new_fd)
 Adds the global controller to be monitored by the socket monitor. More...
 
int monitor_runtime_socket (int new_fd)
 Adds a runtime to be monitored by the socket monitor. More...
 
int run_socket_monitor (int local_port, struct sockaddr_in *ctrl_addr)
 Starts (blocking) the socket monitor, listening on the provided port. More...
 

Variables

static bool runtime_fds [1024]
 Whether the file descriptor has been associated with a runtime. More...
 
int runtime_socket = -1
 The socket on which incoming connections are monitored. More...
 
int epoll_fd = -1
 The epoll file descriptor monitoring sockets. More...
 

Detailed Description

Monitors an incoming port for messages from runtime or controller.

Definition in file socket_monitor.c.

Macro Definition Documentation

#define MAX_RUNTIME_FD   1024

The maximum file descriptor that can be associated with a runtime.

Definition at line 34 of file socket_monitor.c.

Function Documentation

static int accept_connection ( int  fd,
void *  data 
)
static

Accepts a new connection.

Assumes it is a runtime

Definition at line 89 of file socket_monitor.c.

static int handle_connection ( int  fd,
void *  data 
)
static

Checks if the file descriptor is a runtime or controller, and handles it appropraitely.

Definition at line 69 of file socket_monitor.c.

static int init_socket_monitor ( int  port)
static

Initializes the socket monitor on the given port.

Definition at line 44 of file socket_monitor.c.

int monitor_controller_socket ( int  fd)

Adds the global controller to be monitored by the socket monitor.

Parameters
fdthe file decriptor of the global controller
Returns
0 on success, -1 on error

Definition at line 116 of file socket_monitor.c.

int monitor_runtime_socket ( int  fd)

Adds a runtime to be monitored by the socket monitor.

Parameters
fdthe file descriptor of the new runtime
Returns
0 on success, -1 on error

Definition at line 130 of file socket_monitor.c.

int run_socket_monitor ( int  local_port,
struct sockaddr_in *  ctrl_addr 
)

Starts (blocking) the socket monitor, listening on the provided port.

Also connects to the global controller at the provided address

Definition at line 145 of file socket_monitor.c.

static int socket_monitor_epoll_loop ( )
static

The main loop for the socket monitor.

Simply calls epoll_loop

Definition at line 101 of file socket_monitor.c.

Variable Documentation

int epoll_fd = -1

The epoll file descriptor monitoring sockets.

Definition at line 41 of file socket_monitor.c.

bool runtime_fds[1024]
static

Whether the file descriptor has been associated with a runtime.

Definition at line 36 of file socket_monitor.c.

int runtime_socket = -1

The socket on which incoming connections are monitored.

Definition at line 39 of file socket_monitor.c.