otsdaq  v2_01_00
ReceiverSocket.h
1 #ifndef _ots_ReceiverSocket_h_
2 #define _ots_ReceiverSocket_h_
3 
4 #include "otsdaq-core/NetworkUtilities/Socket.h"
5 
6 #include <string>
7 #include <vector>
8 #include <mutex> //for std::mutex
9 
10 namespace ots
11 {
12 
13 class ReceiverSocket : public virtual Socket
14 {
15  //TransceiverSocket is a "Friend" class of ReceiverSocket so has access to private members.
16  friend class TransceiverSocket;
17 public:
18  ReceiverSocket(std::string IPAddress, unsigned int port=0);
19  virtual ~ReceiverSocket(void);
20 
21  int receive(std::string& buffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false);
22  int receive(std::vector<uint32_t>& buffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false);
23  int receive(std::string& buffer, unsigned long& fromIPAddress, unsigned short& fromPort, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false);
24  int receive(std::vector<uint32_t>& buffer, unsigned long& fromIPAddress, unsigned short& fromPort, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=false);
25 
26 protected:
27  ReceiverSocket(void);
28 
29 private:
30  fd_set fileDescriptor_;
31  struct timeval timeout_;
32  struct sockaddr_in fromAddress_;
33  socklen_t addressLength_;
34  int numberOfBytes_;
35 
36  unsigned long dummyIPAddress_;
37  unsigned short dummyPort_;
38  unsigned int readCounter_;
39 
40  std::mutex receiveMutex_; //to make receiver socket thread safe
41  // i.e. multiple threads can share a socket and call receive()
42 
43 };
44 
45 }
46 
47 #endif