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"
32 class TCPSocketTransfer;
85 CopyStatus copyFragment(Fragment& frag,
size_t timeout_usec)
override {
return sendFragment_(std::move(frag), timeout_usec); }
101 static std::atomic<int> listen_thread_refcount_;
102 static std::mutex listen_thread_mutex_;
103 static std::unique_ptr<boost::thread> listen_thread_;
104 static std::map<int, std::set<int>> connected_fds_;
105 static std::mutex connected_fd_mutex_;
107 int active_receive_fd_;
108 int last_active_receive_fd_;
116 enum class SocketState
124 size_t send_retry_timeout_us_;
128 volatile unsigned connect_state : 1;
129 unsigned blocking : 1;
131 bool timeoutMessageArmed_;
132 size_t not_connected_count_;
133 size_t receive_err_threshold_;
134 size_t receive_err_wait_us_;
137 CopyStatus sendFragment_(Fragment&& frag,
size_t timeout_usec);
139 CopyStatus sendData_(
const void* buf,
size_t bytes,
size_t tmo);
141 CopyStatus sendData_(
const struct iovec* iov,
int iovcnt,
size_t tmo);
144 void receive_ack_(
int fd);
145 void send_ack_(
int fd);
153 int disconnect_receive_socket_(
int fd, std::string msg =
"");
156 void start_listen_thread_();
157 static void listen_(
int port,
size_t rcvbuf);
159 int calculate_port_()
const {
165 std::unique_lock<std::mutex> lk(connected_fd_mutex_);
166 return connected_fds_.count(source_rank) ? connected_fds_[
source_rank].size() : 0;
170 #endif // TCPSocketTransfer_hh
bool isRunning() override
Determine whether the TransferInterface plugin is able to send/receive data.
virtual int source_rank() const
Get the source rank for this TransferInterface instance.
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...
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.
std::map< int, DestinationInfo > hostMap_t
The host_map is a map associating ranks with artdaq::DestinationInfo objects.
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.