blob: df16e03af8fd72b2d8c6d6f83d34eecd97945bdc [file] [log] [blame]
David Reiss9f3296b2010-08-31 16:58:41 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#ifndef _THRIFT_TRANSPORT_TZMQCLIENT_H_
21#define _THRIFT_TRANSPORT_TZMQCLIENT_H_ 1
22
23#include <zmq.hpp>
Roger Meier49ff8b12012-04-13 09:12:31 +000024#include <thrift/transport/TBufferTransports.h>
David Reiss9f3296b2010-08-31 16:58:41 +000025
26namespace apache { namespace thrift { namespace transport {
27
28class TZmqClient : public TTransport {
29 public:
30 TZmqClient(zmq::context_t& ctx, const std::string& endpoint, int type)
31 : sock_(ctx, type)
32 , endpoint_(endpoint)
33 , wbuf_()
34 , rbuf_()
35 , msg_()
36 , zmq_type_(type)
37 {}
38
39 void open() {
40 if(zmq_type_ == ZMQ_PUB) {
41 sock_.bind(endpoint_.c_str());
42 }
43 else {
44 sock_.connect(endpoint_.c_str());
45 }
46 }
47
Jens Geyer3e9c3a22014-12-22 22:21:24 +010048 uint32_t read_virt(uint8_t* buf, uint32_t len);
David Reiss9f3296b2010-08-31 16:58:41 +000049
Jens Geyer3e9c3a22014-12-22 22:21:24 +010050 void write_virt(const uint8_t* buf, uint32_t len);
David Reiss9f3296b2010-08-31 16:58:41 +000051
Jens Geyer3e9c3a22014-12-22 22:21:24 +010052 uint32_t writeEnd();
David Reiss9f3296b2010-08-31 16:58:41 +000053
54 protected:
David Reiss9f3296b2010-08-31 16:58:41 +000055 zmq::socket_t sock_;
Jens Geyer3e9c3a22014-12-22 22:21:24 +010056 std::string endpoint_;
David Reiss9f3296b2010-08-31 16:58:41 +000057 TMemoryBuffer wbuf_;
58 TMemoryBuffer rbuf_;
59 zmq::message_t msg_;
60 int zmq_type_;
61};
62
63}}} // apache::thrift::transport
64
65#endif // #ifndef _THRIFT_TRANSPORT_TZMQCLIENT_H_