CppServer  1.0.0.0
C++ Server Library
request_client.h
Go to the documentation of this file.
1 
9 #ifndef CPPSERVER_NANOMSG_REQUEST_CLIENT_H
10 #define CPPSERVER_NANOMSG_REQUEST_CLIENT_H
11 
12 #include "client.h"
13 
14 namespace CppServer {
15 namespace Nanomsg {
16 
18 
44 class RequestClient : public Client
45 {
46 public:
48 
52  explicit RequestClient(const std::string& address, bool threading = false)
53  : Client(CppServer::Nanomsg::Domain::Std, CppServer::Nanomsg::Protocol::Request, address, threading)
54  {}
55  RequestClient(const RequestClient&) = delete;
56  RequestClient(RequestClient&&) = default;
57  virtual ~RequestClient() = default;
58 
59  RequestClient& operator=(const RequestClient&) = delete;
61 
63 
68  Message Request(const void* buffer, size_t size)
69  {
70  Message message;
71  if (Send(buffer, size) == size)
72  Receive(message);
73  return message;
74  }
76 
80  Message Request(const std::string& text) { return Request(text.data(), text.size()); }
82 
86  Message Request(const Message& message) { return Request(message.buffer(), message.size()); }
87 };
88 
91 } // namespace Nanomsg
92 } // namespace CppServer
93 
94 #endif // CPPSERVER_NANOMSG_REQUEST_CLIENT_H
RequestClient(const std::string &address, bool threading=false)
Initialize client with a given endpoint address.
size_t Receive(Message &message)
Receive a message from the server.
Definition: client.cpp:189
Message Request(const void *buffer, size_t size)
Request data to the server.
Nanomsg message.
Definition: message.h:29
size_t size() const noexcept
Get the message size.
Definition: message.h:71
Message Request(const std::string &text)
Request a text string to the server.
C++ Server project definitions.
Definition: asio.h:24
size_t Send(const void *buffer, size_t size)
Send data to the server.
Definition: client.cpp:157
Message Request(const Message &message)
Request a message to the server.
uint8_t * buffer() noexcept
Get the message buffer.
Definition: message.h:67
Protocol
Nanomsg protocol.
Definition: nanomsg.h:56
Nanomsg client.
Definition: client.h:29
Domain
Nanomsg domain.
Definition: nanomsg.h:41
Nanomsg client definition.
Nanomsg request client.
Standard full-blown socket.
RequestClient & operator=(const RequestClient &)=delete