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"
34 class TCPSocketTransfer;
110 static std::atomic<int> listen_thread_refcount_;
111 static std::mutex listen_thread_mutex_;
112 static std::unique_ptr<boost::thread> listen_thread_;
113 static std::map<int, std::set<int>> connected_fds_;
114 static std::mutex connected_fd_mutex_;
116 int active_receive_fd_;
117 int last_active_receive_fd_;
118 short active_revents_;
126 enum class SocketState
134 size_t send_retry_timeout_us_;
138 volatile unsigned connect_state : 1;
139 unsigned blocking : 1;
141 bool timeoutMessageArmed_;
142 std::chrono::steady_clock::time_point last_recv_time_;
143 double receive_disconnected_wait_s_;
144 size_t receive_err_wait_us_;
145 std::atomic<bool> receive_socket_has_been_connected_;
146 std::atomic<int> send_ack_diff_;
147 std::unique_ptr<boost::thread> ack_listen_thread_;
150 CopyStatus sendFragment_(Fragment&& frag,
size_t timeout_usec);
152 CopyStatus sendData_(
const void* buf,
size_t bytes,
size_t tmo,
bool isHeader =
false);
154 CopyStatus sendData_(
const struct iovec* iov,
int iovcnt,
size_t tmo,
bool isHeader =
false);
157 void receive_acks_();
158 void send_ack_(
int fd);
166 int disconnect_receive_socket_(
int fd, std::string msg =
"");
169 void start_listen_thread_();
170 static void listen_(
int port,
size_t rcvbuf);
174 std::unique_lock<std::mutex> lk(connected_fd_mutex_);
175 return connected_fds_.count(source_rank) ? connected_fds_[
source_rank].size() : 0;
179 #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 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.
int receiveFragmentHeader(detail::RawFragmentHeader &header, size_t receiveTimeout) override
Receive a Fragment Header from the transport mechanism.
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.