1 #ifndef TCPSocketTransfer_hh
2 #define TCPSocketTransfer_hh
15 #include <boost/thread.hpp>
16 #include <condition_variable>
19 #include "fhiclcpp/fwd.h"
22 #include "artdaq-core/Data/Fragment.hh"
23 #include "artdaq/TransferPlugins/TransferInterface.hh"
24 #include "artdaq/TransferPlugins/detail/HostMap.hh"
25 #include "artdaq/TransferPlugins/detail/SRSockets.hh"
26 #include "artdaq/TransferPlugins/detail/Timeout.hh"
33 class TCPSocketTransfer;
108 static std::atomic<int> listen_thread_refcount_;
109 static std::mutex listen_thread_mutex_;
110 static std::unique_ptr<boost::thread> listen_thread_;
111 static std::map<int, std::set<int>> connected_fds_;
112 static std::mutex fd_mutex_;
114 std::map<int, int> active_receive_fds_;
115 std::map<int, int> last_active_receive_fds_;
123 enum class SocketState
131 size_t send_retry_timeout_us_;
135 volatile unsigned connect_state : 1;
136 unsigned blocking : 1;
138 bool connection_was_lost_;
140 bool timeoutMessageArmed_;
141 std::chrono::steady_clock::time_point last_recv_time_;
142 double receive_disconnected_wait_s_;
143 size_t receive_err_wait_us_;
144 std::atomic<bool> receive_socket_has_been_connected_;
145 std::atomic<int> send_ack_diff_;
146 std::unique_ptr<boost::thread> ack_listen_thread_;
154 CopyStatus sendFragment_(Fragment&& frag,
size_t timeout_usec);
156 CopyStatus sendData_(
const void* buf,
size_t bytes,
size_t send_timeout_usec,
bool isHeader =
false);
158 CopyStatus sendData_(
const struct iovec* iov,
int iovcnt,
size_t send_timeout_usec,
bool isHeader =
false);
161 void receive_acks_();
162 void send_ack_(
int fd);
170 void disconnect_receive_socket_(
const std::string& msg =
"");
173 void start_listen_thread_();
174 static void listen_(
int port,
size_t rcvbuf);
183 #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.
int receiveFragmentHeader(detail::RawFragmentHeader &header, size_t timeout_usec) override
Receive a Fragment Header from the transport mechanism.
CopyStatus transfer_fragment_reliable_mode(Fragment &&frag) override
Transfer a Fragment to the destination. This should be reliable, if the underlying transport mechanis...
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.
void flush_buffers() override
Flush any in-flight data. This should be used by the receiver after the receive loop has ended...
Role
Used to determine if a TransferInterface is a Sender or Receiver.
This interface defines the functions used to transfer data between artdaq applications.
TransferInterface implementation plugin that sends data using TCP sockets.
This header is sent by the TCPSocket_transfer to allow for more efficient writev calls.
std::map< int, std::string > hostMap_t
The host_map is a map associating ranks with artdaq::DestinationInfo objects.
CopyStatus transfer_fragment_min_blocking_mode(Fragment const &frag, size_t timeout_usec) override
Transfer a Fragment to the destination. May not necessarily be reliable, but will not block longer th...
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.