1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-16 00:00:02 +01:00
VILLASnode/include/villas/nodes/socket.hpp

93 lines
2.7 KiB
C++
Raw Permalink Normal View History

2020-01-21 14:20:49 +01:00
/** The socket node-type for Layer 2, 3, 4 BSD-style sockets
*
* @file
2015-06-02 21:53:04 +02:00
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
2015-09-19 18:48:00 +02:00
/**
* @addtogroup socket BSD Socket Node Type
2015-09-19 18:48:00 +02:00
* @ingroup node
* @{
*/
2017-02-16 09:04:12 -03:00
#pragma once
#include <villas/node/config.h>
2018-08-23 17:37:16 +02:00
#include <villas/node.h>
#include <villas/socket_addr.h>
2018-05-12 15:25:29 +02:00
#include <villas/io.h>
/* Forward declarations */
2018-05-12 13:56:12 +02:00
struct format_type;
/** The maximum length of a packet which contains stuct msg. */
#define SOCKET_INITIAL_BUFFER_LEN (64*1024)
struct socket {
2018-06-29 08:37:14 +02:00
int sd; /**< The socket descriptor */
int verify_source; /**< Verify the source address of incoming packets against socket::remote. */
2019-06-23 16:13:23 +02:00
enum SocketLayer layer; /**< The OSI / IP layer which should be used for this socket */
2018-05-12 13:56:12 +02:00
struct format_type *format;
2018-05-12 15:25:29 +02:00
struct io io;
/* Multicast options */
struct multicast {
2018-06-29 08:37:14 +02:00
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;
};
/** @see node_vtable::type_start */
2019-04-23 13:14:47 +02:00
int socket_type_start(villas::node::SuperNode *sn);
/** @see node_type::type_stop */
int socket_type_stop();
2020-01-21 14:27:28 +01:00
/** @see node_type::start */
2020-08-25 21:00:52 +02:00
int socket_start(struct vnode *n);
2020-01-21 14:27:28 +01:00
/** @see node_type::stop */
2020-08-25 21:00:52 +02:00
int socket_stop(struct vnode *n);
2017-04-18 17:58:23 +02:00
/** @see node_type::write */
2020-08-25 21:00:52 +02:00
int socket_write(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
2017-04-18 17:58:23 +02:00
/** @see node_type::read */
2020-08-25 21:00:52 +02:00
int socket_read(struct vnode *n, struct sample *smps[], unsigned cnt, unsigned *release);
2017-04-18 17:58:23 +02:00
/** @see node_type::parse */
2020-08-25 21:00:52 +02:00
int socket_parse(struct vnode *n, json_t *cfg);
2017-04-18 17:58:23 +02:00
/** @see node_type::print */
2020-08-25 21:00:52 +02:00
char * socket_print(struct vnode *n);
2018-06-29 08:37:14 +02:00
/** @} */