1 #include "otsdaq/NetworkUtilities/TCPTransmitterSocket.h"
3 #include <sys/socket.h>
6 #include "otsdaq/NetworkUtilities/TCPPacket.h"
12 TCPTransmitterSocket::TCPTransmitterSocket(
int socketId) :
TCPSocket(socketId) {}
15 TCPTransmitterSocket::~TCPTransmitterSocket(
void) {}
18 void TCPTransmitterSocket::sendPacket(
char const* buffer, std::size_t size)
20 send(TCPPacket::encode(buffer, size));
24 void TCPTransmitterSocket::sendPacket(
const std::string& buffer)
26 send(TCPPacket::encode(buffer));
30 void TCPTransmitterSocket::send(
char const* buffer,
32 bool forceEmptyPacket)
34 if(size == 0 && !forceEmptyPacket)
36 std::cout << __PRETTY_FUNCTION__ <<
"I am sorry but I won't send an empty packet!"
40 std::size_t totalSent = 0;
41 while(totalSent < size)
44 ::send(getSocketId(), buffer + totalSent, size - totalSent, MSG_NOSIGNAL);
47 totalSent +=
static_cast<std::size_t
>(sentBytes);
53 throw std::runtime_error(
"Write: returned 0 bytes, connection may be closed");
64 throw std::runtime_error(std::string(
"Write: critical error: ") +
74 throw std::runtime_error(std::string(
"Write: resource failure: ") +
84 throw std::runtime_error(std::string(
"Write: returned -1: ") +
92 void TCPTransmitterSocket::send(
const std::string& buffer)
94 send(&buffer.at(0), buffer.size());
98 void TCPTransmitterSocket::send(
const std::vector<char>& buffer)
100 send(&buffer.at(0), buffer.size());
104 void TCPTransmitterSocket::send(
const std::vector<uint16_t>& buffer)
106 send((
const char*)&buffer.at(0), buffer.size());
110 void TCPTransmitterSocket::setSendTimeout(
unsigned int timeoutSeconds,
111 unsigned int timeoutMicroSeconds)
114 tv.tv_sec = timeoutSeconds;
115 tv.tv_usec = timeoutMicroSeconds;
116 setsockopt(getSocketId(), SOL_SOCKET, SO_SNDTIMEO, (
const char*)&tv,
sizeof tv);
defines used also by OtsConfigurationWizardSupervisor