General-purpose socket communication functions used from global controller, runtime, or MSUs. More...
Go to the source code of this file.
Macros | |
| #define | MAX_READ_ATTEMPTS 100 |
The maximum number of times that a call to read() can be attempted for a single buffer before giving up. More... | |
| #define | BACKLOG 1024 |
| The backlog size for listening sockets. More... | |
Functions | |
| int | read_payload (int fd, size_t size, void *buff) |
| Reads a buffer of a given size from a file descriptor. More... | |
| ssize_t | send_to_endpoint (int fd, void *data, size_t data_len) |
| Writes a buffer of a given size to a file descriptor. More... | |
| int | init_connected_socket (struct sockaddr_in *addr) |
| Initializes a socket that is connected to a given address. More... | |
| int | init_bound_socket (int port) |
| Initializes a socket which is bound to a given port (and any local IP address). More... | |
| int | init_listening_socket (int port) |
| Initializes a socket which is bound to and listening on the given port. More... | |
General-purpose socket communication functions used from global controller, runtime, or MSUs.
Definition in file communication.c.
| #define BACKLOG 1024 |
The backlog size for listening sockets.
Definition at line 145 of file communication.c.
| #define MAX_READ_ATTEMPTS 100 |
The maximum number of times that a call to read() can be attempted for a single buffer before giving up.
Definition at line 35 of file communication.c.
| int init_bound_socket | ( | int | port | ) |
Initializes a socket which is bound to a given port (and any local IP address).
Sets REUSEPORT and REUSEADDR on the socket.
| port | The port to which to bind |
Definition at line 114 of file communication.c.
| int init_connected_socket | ( | struct sockaddr_in * | addr | ) |
Initializes a socket that is connected to a given address.
Blocks until the connection has been estabslished. Sets port and address to be reusable
| addr | The address to connect to |
Definition at line 81 of file communication.c.
| int init_listening_socket | ( | int | port | ) |
Initializes a socket which is bound to and listening on the given port.
Sets backlog on socket to be equal to BACKLOG
| port | The port on which to listen |
Definition at line 147 of file communication.c.
| int read_payload | ( | int | fd, |
| size_t | size, | ||
| void * | buff | ||
| ) |
Reads a buffer of a given size from a file descriptor.
Loops until enough bytes have been read off of the socket, until the socket is closed, or until it has tried more than MAX_READ_ATTEMPTS times.
| fd | The file descriptor from which to read |
| size | The number of bytes to read off of the file desriptor |
| buff | The buffer into which the read the bytes |
Definition at line 37 of file communication.c.
| ssize_t send_to_endpoint | ( | int | fd, |
| void * | data, | ||
| size_t | data_len | ||
| ) |
Writes a buffer of a given size to a file descriptor.
Loops on the write call until all of the bytes have been sent or it encounters an error.
| fd | The file descriptor to which the data is to be written |
| data | The buffer to write to the file descriptor |
| data_len | The size of the buffer to write |
Definition at line 66 of file communication.c.
1.8.6