zmqpp  4.1.2
C++ bindings for 0mq (libzmq)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
zap_handler.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  *
6  * This file is part of zmqpp.
7  * Copyright (c) 2011-2015 Contributors as noted in the AUTHORS file.
8  */
9 
10 
11 // Authentication is something from zmq 4
12 #if (ZMQ_VERSION_MAJOR > 3)
13 
14 namespace zmqpp
15 {
27 template<typename RequestHandler>
29 {
30 
31 public:
32 
33 zap_handler(RequestHandler &handler) :
34 handler_(handler),
35 actor_(std::bind(&run_zap_handler, this, std::placeholder::_1))
36 {
37 
38 }
39 
40 private:
41 
43 {
44 while (run_)
45 {
46  // Receive a ZAP request.
47  zap_request request(sock, verbose);
48 
49  if(request.get_version().empty())
50  {
51  request.reply("500", "Internal error");
52  continue;
53  }
54 
55  zmqpp::message zap_response;
56  zap_response = handler_(request);
57 
58 }
59 
60 }
61 
62 RequestHandler &handler_;
63 actor_t actor_;
64  constexpr static const char * const zap_endpoint_ = "inproc://zeromq.zap.01";
65 };
66 
67 }
actor_t actor_
Definition: zap_handler.hpp:63
A class for working with ZAP requests and replies.
Definition: zap_request.hpp:33
A base ZAP handler object.
Definition: zap_handler.hpp:28
C++ wrapper around zmq.
Definition: actor.cpp:29
zap_handler(RequestHandler &handler)
Definition: zap_handler.hpp:33
STL namespace.
The socket class represents the zmq sockets.
Definition: socket.hpp:75
const std::string & get_version() const
Get Version.
Definition: zap_request.hpp:49
void reply(const std::string &status_code, const std::string &status_text, const std::string &user_id)
Send a ZAP reply to the handler socket.
Definition: zap_request.cpp:72
static constexpr const char *const zap_endpoint_
Definition: zap_handler.hpp:64
bool run_zap_handler(zmqpp::socket *pipe)
Definition: zap_handler.hpp:42
RequestHandler & handler_
Definition: zap_handler.hpp:62
a zmq message with optional multipart support
Definition: message.hpp:43