1 #ifndef _ots_TCPSocket_h_
2 #define _ots_TCPSocket_h_
5 #include <netinet/in.h>
10 #include "artdaq/DAQdata/TCPConnect.hh"
11 #include "artdaq/DAQdata/TCP_listen_fd.hh"
13 #define OTS_MAGIC 0x5F4F54534441515F
21 TCPSocket(
const std::string &senderHost,
unsigned int senderPort,
int receiveBufferSize = 0x10000);
22 TCPSocket(
unsigned int listenPort,
int sendBufferSize = 0x10000);
27 int send(
const uint8_t* data,
size_t size);
28 int send(
const std::string& buffer);
29 int send(
const std::vector<uint32_t>& buffer);
30 int send(
const std::vector<uint16_t>& buffer);
32 int receive(uint8_t* buffer,
unsigned int timeoutSeconds,
unsigned int timeoutUSeconds);
33 int receive(std::string& buffer,
unsigned int timeoutSeconds = 1,
unsigned int timeoutUSeconds = 0);
34 int receive(std::vector<uint32_t>& buffer,
unsigned int timeoutSeconds = 1,
unsigned int timeoutUSeconds = 0);
49 mutable std::mutex socketMutex_;
55 unsigned int dest_port;
57 MagicPacket makeMagicPacket(
unsigned int port)
60 m.ots_magic = OTS_MAGIC;
64 bool checkMagicPacket(MagicPacket magic)
66 return magic.ots_magic == OTS_MAGIC && magic.dest_port == port_;