1 #include "otsdaq/NetworkUtilities/TransmitterSocket.h"
2 #include "otsdaq/Macros/CoutMacros.h"
3 #include "otsdaq/MessageFacility/MessageFacility.h"
12 TransmitterSocket::TransmitterSocket(
void)
14 __COUT__ <<
"TransmitterSocket constructor " << __E__;
18 TransmitterSocket::TransmitterSocket(
const std::string& IPAddress,
unsigned int port)
21 __COUT__ <<
"TransmitterSocket constructor " << IPAddress <<
":" << port << __E__;
25 TransmitterSocket::~TransmitterSocket(
void) {}
28 int TransmitterSocket::send(
Socket& toSocket,
const std::string& buffer,
bool verbose)
31 std::lock_guard<std::mutex> lock(sendMutex_);
37 constexpr
size_t MAX_SEND_SIZE = 65500;
41 while(offset < buffer.size() && sts > 0)
43 auto thisSize = buffer.size() - offset > MAX_SEND_SIZE ? MAX_SEND_SIZE
44 : buffer.size() - offset;
48 __COUT__ <<
"Sending "
49 <<
" from: " << getIPAddress() <<
":"
50 << ntohs(socketAddress_.sin_port)
51 <<
" to: " << toSocket.getIPAddress() <<
":"
52 << ntohs(toSocket.getSocketAddress().sin_port)
53 <<
" size: " << thisSize
54 <<
" remaining = " << (buffer.size() - offset - thisSize)
74 sts = sendto(socketNumber_,
75 buffer.c_str() + offset,
78 (
struct sockaddr*)&(toSocket.getSocketAddress()),
85 __SS__ <<
"Error writing buffer for port " << ntohs(socketAddress_.sin_port)
86 <<
": " << strerror(errno)
87 <<
". Was this tx socket initialized with Socket::Initialize()?" << __E__;
94 int TransmitterSocket::send(
Socket& toSocket,
95 const std::vector<uint16_t>& buffer,
99 std::lock_guard<std::mutex> lock(sendMutex_);
105 constexpr
size_t MAX_SEND_SIZE = 1500;
109 while(offset < buffer.size() && sts > 0)
111 auto thisSize = 2 * (buffer.size() - offset) > MAX_SEND_SIZE
113 : 2 * (buffer.size() - offset);
114 sts = sendto(socketNumber_,
118 (
struct sockaddr*)&(toSocket.getSocketAddress()),
119 sizeof(sockaddr_in));
125 __SS__ <<
"Error writing buffer for port " << ntohs(socketAddress_.sin_port)
126 <<
": " << strerror(errno)
127 <<
". Was this tx socket initialized with Socket::Initialize()?" << __E__;
134 int TransmitterSocket::send(
Socket& toSocket,
135 const std::vector<uint32_t>& buffer,
139 std::lock_guard<std::mutex> lock(sendMutex_);
145 if(sendto(socketNumber_,
147 buffer.size() *
sizeof(uint32_t),
149 (
struct sockaddr*)&(toSocket.getSocketAddress()),
150 sizeof(sockaddr_in)) < (
int)(buffer.size() *
sizeof(uint32_t)))
152 __SS__ <<
"Error writing buffer for port " << ntohs(socketAddress_.sin_port)
153 <<
". Was this tx socket initialized with Socket::Initialize()?" << __E__;