Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
GcTcpHub.cxx
Go to the documentation of this file.
1
34#include "utils/GcTcpHub.hxx"
35
36#include <memory>
37
38#include "nmranet_config.h"
40#include "utils/FdUtils.hxx"
41
43{
44 const bool use_select =
45 (config_gridconnect_tcp_use_select() == CONSTANT_TRUE);
46 {
47 AtomicHolder h(this);
49 }
50 // Applies kernel parameters like socket options.
52 create_gc_port_for_can_hub(canHub_, fd, this, use_select);
53}
54
56{
57 AtomicHolder h(this);
58 if (numClients_)
59 {
61 }
62}
63
64GcTcpHub::GcTcpHub(CanHubFlow *can_hub, int port)
65 : canHub_(can_hub)
66 , tcpListener_(port,
67 std::bind(&GcTcpHub::on_new_connection, this, std::placeholders::_1),
68 "GcTcpHub")
69{
70}
71
72GcTcpHub::~GcTcpHub()
73{
75}
void create_gc_port_for_can_hub(CanHubFlow *can_hub, int fd, Notifiable *on_exit, bool use_select)
Creates a new port on a CAN hub in gridconnect format for a select-compatible file descriptor.
int bind(int socket, const struct sockaddr *address, socklen_t address_len)
Bind a name to a socket.
Definition Socket.cxx:159
See OSMutexLock in os/OS.hxx.
Definition Atomic.hxx:153
This class runs a CAN-bus HUB listening on TCP socket using the gridconnect format.
Definition GcTcpHub.hxx:47
unsigned numClients_
How many clients are connected right now.
Definition GcTcpHub.hxx:84
GcTcpHub(CanHubFlow *can_hub, int port)
Constructor.
Definition GcTcpHub.cxx:64
SocketListener tcpListener_
Helper object representing the listening on the socket.
Definition GcTcpHub.hxx:86
void notify() override
Error callback from the gridconnect socket.
Definition GcTcpHub.cxx:55
void on_new_connection(int fd)
Callback when a new connection arrives.
Definition GcTcpHub.cxx:42
CanHubFlow * canHub_
Definition GcTcpHub.hxx:82
void shutdown()
Shuts down the socket listener.
#define CONSTANT_TRUE
We cannot compare constants to zero, so we use 1 and 2 as constant values for booleans.
static void optimize_socket_fd(int fd)
Optimizes the kernel settings like socket and TCP options for an fd that is an outgoing TCP socket.
Definition FdUtils.cxx:67