Source · fairmq/
Socket.hpublic header
Defines struct fair::mq::Socket, struct fair::mq::SocketError, struct fair::mq::is_transferrable.
Described in Handle errors and timeouts, Transfer codes and errors.
1/********************************************************************************2 * Copyright (C) 2021-2022 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 FAIR_MQ_SOCKET_H10#define FAIR_MQ_SOCKET_H11 12#include <fairmq/Message.h>13#include <fairmq/Parts.h>14 15#include <memory>16#include <stdexcept>17#include <string>18#include <type_traits>19#include <vector>20 21namespace fair::mq {22 23class TransportFactory;24 25enum class TransferCode : int26{27 success = 0,28 error = -1,29 timeout = -2,30 interrupted = -331};32 33template <typename T>34struct is_transferrable : std::disjunction<std::is_same<T, MessagePtr>,35 std::is_same<T, std::vector<MessagePtr>>,36 std::is_same<T, fair::mq::Parts>>37{};38 39struct Socket40{41 Socket() = default;42 Socket(TransportFactory* fac) : fTransport(fac) {}43 Socket(const Socket&) = delete;44 Socket(Socket&&) = delete;45 Socket& operator=(const Socket&) = delete;46 Socket& operator=(Socket&&) = delete;47 48 virtual std::string GetId() const = 0;49 50 virtual bool Bind(const std::string& address) = 0;51 virtual bool Connect(const std::string& address) = 0;52 53 virtual int64_t Send(MessagePtr& msg, int timeout = -1) = 0;54 virtual int64_t Receive(MessagePtr& msg, int timeout = -1) = 0;55 virtual int64_t Send(Parts::container& msgVec, int timeout = -1) = 0;56 virtual int64_t Receive(Parts::container & msgVec, int timeout = -1) = 0;57 virtual int64_t Send(Parts& parts, int timeout = -1) { return Send(parts.fParts, timeout); }58 virtual int64_t Receive(Parts& parts, int timeout = -1) { return Receive(parts.fParts, timeout); }59 60 [[deprecated("Use Socket::~Socket() instead.")]]61 virtual void Close() = 0;62 63 virtual void SetOption(const std::string& option, const void* value, size_t valueSize) = 0;64 virtual void GetOption(const std::string& option, void* value, size_t* valueSize) = 0;65 66 /// If the backend supports it, fills the unsigned integer @a events with the ZMQ_EVENTS value67 /// DISCLAIMER: this API is experimental and unsupported and might be dropped / refactored in68 /// the future.69 virtual int Events(uint32_t* events) = 0;70 virtual void SetLinger(int value) = 0;71 virtual int GetLinger() const = 0;72 virtual void SetSndBufSize(int value) = 0;73 virtual int GetSndBufSize() const = 0;74 virtual void SetRcvBufSize(int value) = 0;75 virtual int GetRcvBufSize() const = 0;76 virtual void SetSndKernelSize(int value) = 0;77 virtual int GetSndKernelSize() const = 0;78 virtual void SetRcvKernelSize(int value) = 0;79 virtual int GetRcvKernelSize() const = 0;80 81 virtual unsigned long GetBytesTx() const = 0;82 virtual unsigned long GetBytesRx() const = 0;83 virtual unsigned long GetMessagesTx() const = 0;84 virtual unsigned long GetMessagesRx() const = 0;85 86 virtual unsigned long GetNumberOfConnectedPeers() const = 0;87 88 TransportFactory* GetTransport() { return fTransport; }89 void SetTransport(TransportFactory* transport) { fTransport = transport; }90 91 virtual ~Socket() = default;92 93 private:94 TransportFactory* fTransport{nullptr};95};96 97using SocketPtr = std::unique_ptr<Socket>;98 99struct SocketError : std::runtime_error100{101 using std::runtime_error::runtime_error;102};103 104} // namespace fair::mq105 106using FairMQSocket [[deprecated("Use fair::mq::Socket")]] = fair::mq::Socket;107using FairMQSocketPtr [[deprecated("Use fair::mq::SocketPtr")]] = fair::mq::SocketPtr;108 109#endif // FAIR_MQ_SOCKET_H