1 #ifndef _ots_TCPSocket_h_
2 #define _ots_TCPSocket_h_
4 #include <netinet/in.h>
10 #include "artdaq/DAQdata/TCPConnect.hh"
11 #include "artdaq/DAQdata/TCP_listen_fd.hh"
13 #define OTS_MAGIC 0x5F4F54534441515F
21 unsigned int senderPort,
22 int receiveBufferSize = 0x10000);
23 TCPSocket(
unsigned int listenPort,
int sendBufferSize = 0x10000);
26 void connect(
double tmo_s = 10.0);
28 int send(
const uint8_t* data,
size_t size);
29 int send(
const std::string& buffer);
30 int send(
const std::vector<uint32_t>& buffer);
31 int send(
const std::vector<uint16_t>& buffer);
33 int receive(uint8_t* buffer,
34 unsigned int timeoutSeconds,
35 unsigned int timeoutUSeconds);
36 int receive(std::string& buffer,
37 unsigned int timeoutSeconds = 1,
38 unsigned int timeoutUSeconds = 0);
39 int receive(std::vector<uint32_t>& buffer,
40 unsigned int timeoutSeconds = 1,
41 unsigned int timeoutUSeconds = 0);
55 mutable std::mutex socketMutex_;
61 unsigned int dest_port;
63 MagicPacket makeMagicPacket(
unsigned int port)
66 m.ots_magic = OTS_MAGIC;
70 bool checkMagicPacket(MagicPacket magic)
72 return magic.ots_magic == OTS_MAGIC && magic.dest_port == port_;