FairMQ  1.2.0
C++ Message Passing Framework
FairMQSocketZMQ.h
1 /********************************************************************************
2  * Copyright (C) 2014-2018 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIRMQSOCKETZMQ_H_
10 #define FAIRMQSOCKETZMQ_H_
11 
12 #include <atomic>
13 
14 #include <memory> // unique_ptr
15 
16 #include "FairMQSocket.h"
17 #include "FairMQMessage.h"
18 
20 {
21  public:
22  FairMQSocketZMQ(const std::string& type, const std::string& name, const std::string& id = "", void* context = nullptr);
23  FairMQSocketZMQ(const FairMQSocketZMQ&) = delete;
24  FairMQSocketZMQ operator=(const FairMQSocketZMQ&) = delete;
25 
26  std::string GetId() override;
27 
28  bool Bind(const std::string& address) override;
29  void Connect(const std::string& address) override;
30 
31  int Send(FairMQMessagePtr& msg, const int timeout = 0) override;
32  int Receive(FairMQMessagePtr& msg, const int timeout = 0) override;
33  int64_t Send(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
34  int64_t Receive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int timeout = 0) override;
35 
36  int TrySend(FairMQMessagePtr& msg) override;
37  int TryReceive(FairMQMessagePtr& msg) override;
38  int64_t TrySend(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
39  int64_t TryReceive(std::vector<std::unique_ptr<FairMQMessage>>& msgVec) override;
40 
41  void* GetSocket() const override;
42  int GetSocket(int nothing) const override;
43 
44  void Close() override;
45 
46  static void Interrupt();
47  static void Resume();
48 
49  void SetOption(const std::string& option, const void* value, size_t valueSize) override;
50  void GetOption(const std::string& option, void* value, size_t* valueSize) override;
51 
52  unsigned long GetBytesTx() const override;
53  unsigned long GetBytesRx() const override;
54  unsigned long GetMessagesTx() const override;
55  unsigned long GetMessagesRx() const override;
56 
57  bool SetSendTimeout(const int timeout, const std::string& address, const std::string& method) override;
58  int GetSendTimeout() const override;
59  bool SetReceiveTimeout(const int timeout, const std::string& address, const std::string& method) override;
60  int GetReceiveTimeout() const override;
61 
62  static int GetConstant(const std::string& constant);
63 
64  ~FairMQSocketZMQ() override;
65 
66  private:
67  void* fSocket;
68  std::string fId;
69  std::atomic<unsigned long> fBytesTx;
70  std::atomic<unsigned long> fBytesRx;
71  std::atomic<unsigned long> fMessagesTx;
72  std::atomic<unsigned long> fMessagesRx;
73 
74  static std::atomic<bool> fInterrupted;
75 
76  int fSndTimeout;
77  int fRcvTimeout;
78 
79  int SendImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
80  int ReceiveImpl(FairMQMessagePtr& msg, const int flags, const int timeout);
81 
82  int64_t SendImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
83  int64_t ReceiveImpl(std::vector<std::unique_ptr<FairMQMessage>>& msgVec, const int flags, const int timeout);
84 };
85 
86 #endif /* FAIRMQSOCKETZMQ_H_ */
Definition: FairMQSocketZMQ.h:19
Definition: FairMQSocket.h:18