FairMQ  1.4.14
C++ Message Queuing Library and Framework
Socket.h
1 /********************************************************************************
2  * Copyright (C) 2014 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 #ifndef FAIR_MQ_SHMEM_SOCKET_H_
9 #define FAIR_MQ_SHMEM_SOCKET_H_
10 
11 #include "Manager.h"
12 
13 #include <FairMQSocket.h>
14 #include <FairMQMessage.h>
15 
16 #include <atomic>
17 #include <memory> // unique_ptr
18 
20 
21 namespace fair
22 {
23 namespace mq
24 {
25 namespace shmem
26 {
27 
28 class Socket final : public fair::mq::Socket
29 {
30  public:
31  Socket(Manager& manager, const std::string& type, const std::string& name, const std::string& id = "", void* context = nullptr, FairMQTransportFactory* fac = nullptr);
32  Socket(const Socket&) = delete;
33  Socket operator=(const Socket&) = delete;
34 
35  std::string GetId() const override { return fId; }
36 
37  bool Bind(const std::string& address) override;
38  bool Connect(const std::string& address) override;
39 
40  int Send(MessagePtr& msg, const int timeout = -1) override;
41  int Receive(MessagePtr& msg, const int timeout = -1) override;
42  int64_t Send(std::vector<MessagePtr>& msgVec, const int timeout = -1) override;
43  int64_t Receive(std::vector<MessagePtr>& msgVec, const int timeout = -1) override;
44 
45  void* GetSocket() const { return fSocket; }
46 
47  void Close() override;
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  void SetLinger(const int value) override;
53  int GetLinger() const override;
54  void SetSndBufSize(const int value) override;
55  int GetSndBufSize() const override;
56  void SetRcvBufSize(const int value) override;
57  int GetRcvBufSize() const override;
58  void SetSndKernelSize(const int value) override;
59  int GetSndKernelSize() const override;
60  void SetRcvKernelSize(const int value) override;
61  int GetRcvKernelSize() const override;
62 
63  unsigned long GetBytesTx() const override { return fBytesTx; }
64  unsigned long GetBytesRx() const override { return fBytesRx; }
65  unsigned long GetMessagesTx() const override { return fMessagesTx; }
66  unsigned long GetMessagesRx() const override { return fMessagesRx; }
67 
68  static int GetConstant(const std::string& constant);
69 
70  ~Socket() override { Close(); }
71 
72  private:
73  void* fSocket;
74  Manager& fManager;
75  std::string fId;
76  std::atomic<unsigned long> fBytesTx;
77  std::atomic<unsigned long> fBytesRx;
78  std::atomic<unsigned long> fMessagesTx;
79  std::atomic<unsigned long> fMessagesRx;
80 
81  int fSndTimeout;
82  int fRcvTimeout;
83 };
84 
85 }
86 }
87 }
88 
89 #endif /* FAIR_MQ_SHMEM_SOCKET_H_ */
Definition: Manager.h:46
Definition: FairMQTransportFactory.h:30
Definition: FairMQSocket.h:19
Definition: Socket.h:28
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy