otsdaq  v2_05_02_indev
TCPTransmitterSocket.h
1 #ifndef _ots_TCPTransmitterSocket_h_
2 #define _ots_TCPTransmitterSocket_h_
3 
4 #include <iostream>
5 #include <string>
6 #include <vector>
7 #include "otsdaq/NetworkUtilities/TCPSocket.h"
8 
9 namespace ots
10 {
11 // A class that can write to a socket
12 class TCPTransmitterSocket : public virtual TCPSocket
13 {
14  public:
15  TCPTransmitterSocket(int socketId = invalidSocketId);
16  virtual ~TCPTransmitterSocket(void);
17  // TCPTransmitterSocket(TCPTransmitterSocket const&) = delete ;
18  TCPTransmitterSocket(TCPTransmitterSocket&& theTCPTransmitterSocket) = default;
19 
20  void send(char const* buffer, std::size_t size);
21  void send(const std::string& buffer);
22  void send(const std::vector<char>& buffer);
23  void send(const std::vector<uint16_t>& buffer);
24 
25  template<typename T>
26  void send(const std::vector<T>& buffer)
27  {
28  if(buffer.size() == 0)
29  {
30  std::cout << __PRETTY_FUNCTION__ << "I am sorry but I won't send an empty packet!" << std::endl;
31  return;
32  }
33  send(reinterpret_cast<const char*>(&buffer.at(0)), buffer.size() * sizeof(T));
34  }
35 
36  void sendPacket(char const* buffer, std::size_t size);
37  void sendPacket(const std::string& buffer);
38  void setSendTimeout(unsigned int timeoutSeconds, unsigned int timeoutMicroSeconds);
39 };
40 } // namespace ots
41 #endif