otsdaq  v1_01_03
 All Classes Namespaces Functions
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 public:
16  ReceiverSocket(std::string IPAddress, unsigned int port=0);
17  virtual ~ReceiverSocket(void);
18 
19  int receive(std::string& buffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=true);
20  int receive(std::vector<uint32_t>& buffer, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=true);
21  int receive(std::string& buffer, unsigned long& fromIPAddress, unsigned short& fromPort, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=true);
22  int receive(std::vector<uint32_t>& buffer, unsigned long& fromIPAddress, unsigned short& fromPort, unsigned int timeoutSeconds=1, unsigned int timeoutUSeconds=0, bool verbose=true);
23 
24 protected:
25  ReceiverSocket(void);
26 
27 private:
28  fd_set fileDescriptor_;
29  struct timeval timeout_;
30  struct sockaddr_in fromAddress_;
31  socklen_t addressLength_;
32  int numberOfBytes_;
33 
34  unsigned long dummyIPAddress_;
35  unsigned short dummyPort_;
36  unsigned int readCounter_;
37 
38  std::mutex receiveMutex_; //to make receiver socket thread safe
39  // i.e. multiple threads can share a socket and call receive()
40 
41 };
42 
43 }
44 
45 #endif