2023-09-04 12:21:37 +02:00
|
|
|
/* The socket node-type for Layer 2, 3, 4 BSD-style sockets.
|
2014-12-05 12:30:48 +01:00
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2017-03-03 20:20:13 -04:00
|
|
|
*/
|
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/format.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/node/config.hpp>
|
|
|
|
#include <villas/socket_addr.hpp>
|
2017-08-14 14:42:07 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2021-06-21 16:11:42 -04:00
|
|
|
// Forward declarations
|
2021-08-10 10:12:48 -04:00
|
|
|
class NodeCompat;
|
2021-06-21 16:11:42 -04:00
|
|
|
|
2017-08-14 14:42:07 +02:00
|
|
|
// The maximum length of a packet which contains stuct msg.
|
2023-09-07 11:46:39 +02:00
|
|
|
#define SOCKET_INITIAL_BUFFER_LEN (64 * 1024)
|
2017-08-14 14:42:07 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
struct Socket {
|
2023-09-07 11:46:39 +02:00
|
|
|
int sd; // The socket descriptor
|
2024-12-19 15:09:19 +00:00
|
|
|
int clt_sd; // TCP client socket descriptor
|
2023-09-07 11:46:39 +02:00
|
|
|
int verify_source; // Verify the source address of incoming packets against socket::remote.
|
2025-01-29 12:07:42 +00:00
|
|
|
bool tcp_connected = false; // TCP connection status bit
|
2023-09-07 11:46:39 +02:00
|
|
|
|
|
|
|
enum SocketLayer
|
|
|
|
layer; // The OSI / IP layer which should be used for this socket
|
|
|
|
|
|
|
|
Format *formatter;
|
|
|
|
|
|
|
|
// Multicast options
|
|
|
|
struct multicast {
|
|
|
|
int enabled; // Is multicast enabled?
|
|
|
|
unsigned char loop; // Loopback multicast packets to local host?
|
|
|
|
unsigned char ttl; // The time to live for multicast packets.
|
|
|
|
struct ip_mreq mreq; // A multicast group to join.
|
|
|
|
} multicast;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
char *buf; // Buffer for receiving messages
|
|
|
|
size_t buflen;
|
|
|
|
union sockaddr_union saddr; // Remote address of the socket
|
|
|
|
} in, out;
|
2014-12-05 12:30:48 +01:00
|
|
|
};
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_type_start(SuperNode *sn);
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2018-07-16 08:08:17 +02:00
|
|
|
int socket_type_stop();
|
2015-05-06 11:48:30 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_init(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_destroy(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_start(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_check(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_stop(NodeCompat *n);
|
|
|
|
|
|
|
|
int socket_reverse(NodeCompat *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_fds(NodeCompat *n, int fds[]);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int socket_write(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
int socket_read(NodeCompat *n, struct Sample *const smps[], unsigned cnt);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
int socket_parse(NodeCompat *n, json_t *json);
|
2015-03-31 13:48:41 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
char *socket_print(NodeCompat *n);
|
2014-12-05 12:30:48 +01:00
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace node
|
|
|
|
} // namespace villas
|