1 #ifndef TCPSocketTransfer_hh
2 #define TCPSocketTransfer_hh
15 #include <condition_variable>
16 #include <boost/thread.hpp>
19 #include "fhiclcpp/fwd.h"
22 #include "artdaq/TransferPlugins/TransferInterface.hh"
23 #include "artdaq/TransferPlugins/detail/SRSockets.hh"
24 #include "artdaq/TransferPlugins/detail/Timeout.hh"
25 #include "artdaq-core/Data/Fragment.hh"
26 #include "artdaq/TransferPlugins/detail/HostMap.hh"
30 class TCPSocketTransfer;
83 CopyStatus copyFragment(Fragment& frag,
size_t timeout_usec)
override {
return sendFragment_(std::move(frag), timeout_usec); }
94 static std::atomic<int> listen_thread_refcount_;
95 static std::mutex listen_thread_mutex_;
96 static std::unique_ptr<boost::thread> listen_thread_;
97 static std::map<int, std::set<int>> connected_fds_;
99 int active_receive_fd_;
100 int last_active_receive_fd_;
108 enum class SocketState
116 size_t send_retry_timeout_us_;
120 volatile unsigned connect_state : 1;
121 unsigned blocking : 1;
125 bool stats_connect_stop_;
126 boost::thread stats_connect_thread_;
127 std::condition_variable stopstatscv_;
128 std::mutex stopstatscvm_;
130 bool timeoutMessageArmed_;
131 size_t not_connected_count_;
132 size_t receive_err_threshold_;
133 size_t receive_err_wait_us_;
136 CopyStatus sendFragment_(Fragment&& frag,
size_t timeout_usec);
138 CopyStatus sendData_(
const void* buf,
size_t bytes,
size_t tmo);
140 CopyStatus sendData_(
const struct iovec* iov,
int iovcnt,
size_t tmo);
143 void stats_connect_();
151 void start_listen_thread_();
154 int calculate_port_()
const {
159 #endif // TCPSocketTransfer_hh
Role role() const
Get the TransferInterface::Role of this TransferInterface.
CopyStatus copyFragment(Fragment &frag, size_t timeout_usec) override
Copy a Fragment to the destination. Same implementation as moveFragment, as TCP is always reliable...
The Timeout class performs registered actions at specified intervals.
const short partition_number_
The partition number of the DAQ.
int receiveFragmentData(RawDataType *destination, size_t wordCount) override
Receive the body of a Fragment to the given destination pointer.
TCPSocketTransfer(fhicl::ParameterSet const &ps, Role role)
TCPSocketTransfer Constructor.
int receiveFragmentHeader(detail::RawFragmentHeader &header, size_t receiveTimeout) override
Receive a Fragment Header from the transport mechanism.
Role
Used to determine if a TransferInterface is a Sender or Receiver.
CopyStatus moveFragment(Fragment &&frag) override
Move a Fragment to the destination.
This interface defines the functions used to transfer data between artdaq applications.
virtual int destination_rank() const
Get the destination rank for this TransferInterface instance.
TransferInterface implementation plugin that sends data using TCP sockets.
This header is sent by the TCPSocket_transfer to allow for more efficient writev calls.
CopyStatus
Returned from the send functions, this enumeration describes the possible return codes. If an exception occurs, it will be thrown and should be handled normally.