9#include <TInetAddress.h>
16#include <netinet/in.h>
17#include <sys/socket.h>
48 if (!address.IsValid()) {
49 return StatusCode::FAILURE;
53 const UInt_t adr = htonl(address.GetAddress());
57 struct servent sp_buf;
60 getservbyport_r(htons(port),
"tcp", &sp_buf, buf,
sizeof(buf), &
sp);
68 m_socket = ::socket(AF_INET, SOCK_STREAM, 0);
70 return StatusCode::FAILURE;
74 struct sockaddr_in server;
75 memset(&server, 0,
sizeof(server));
76 memcpy(&server.sin_addr, &adr,
sizeof(adr));
77 server.sin_family = address.GetFamily();
78 server.sin_port = sport;
82 sizeof(server)) < 0) {
84 return StatusCode::FAILURE;
88 return StatusCode::SUCCESS;
95 return StatusCode::RECOVERABLE;
100 return StatusCode::FAILURE;
105 return StatusCode::SUCCESS;
123 return StatusCode::FAILURE;
127 const char* buffer = payload.Data();
129 const auto length = payload.Length();
134 for (
int i = 0; i <
length; i += sent) {
137 return StatusCode::FAILURE;
138 }
else if (sent == 0) {
144 return StatusCode::SUCCESS;
151 return StatusCode::FAILURE;
155 auto buffer = std::make_unique<char[]>(maxSize);
158 const auto n = ::recv(
m_socket, buffer.get(), maxSize, 0);
160 return StatusCode::FAILURE;
164 response = TString(buffer.get(),
static_cast<Ssiz_t
>(n));
165 return StatusCode::SUCCESS;
StatusCode send(const TString &payload)
Function sending a message to the connected address.
StatusCode connect(const TInetAddress &address, int port)
Function connecting to the specified address.
StatusCode receive(std::size_t maxSize, TString &response)
Function receiving a message from the connected address.
TSocket()
Constructor with an address and a port.
bool isConnected() const
Check if the socket is connected to some address at the moment.
StatusCode close()
Close the current connection.
int m_socket
The underlying socket.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.