| cpp_redis 4.0.0 cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.

tcp_client_iface.hpp
1 // MIT License
2 //
3 // Copyright (c) 2016-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22
23 #pragma once
24
25 #include <cstdint>
26 #include <functional>
27 #include <string>
28 #include <vector>
29
30 namespace cpp_redis {
31
32 namespace network {
33
37 class tcp_client_iface {
38 public:
40 tcp_client_iface(void) = default;
42 virtual ~tcp_client_iface(void) = default;
43
44 public:
52 virtual void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_msecs = 0) = 0;
53
59 virtual void disconnect(bool wait_for_removal = false) = 0;
60
64 virtual bool is_connected(void) const = 0;
65
66 public:
70 struct read_result {
74 bool success;
75
79 std::vector<char> buffer;
80 };
81
85 struct write_result {
89 bool success;
90
94 std::size_t size;
95 };
96
97 public:
102 typedef std::function<void(read_result&)> async_read_callback_t;
103
108 typedef std::function<void(write_result&)> async_write_callback_t;
109
110 public:
114 struct read_request {
118 std::size_t size;
119
123 async_read_callback_t async_read_callback;
124 };
125
129 struct write_request {
133 std::vector<char> buffer;
134
138 async_write_callback_t async_write_callback;
139 };
140
141 public:
147 virtual void async_read(read_request& request) = 0;
148
154 virtual void async_write(write_request& request) = 0;
155
156 public:
160 typedef std::function<void()> disconnection_handler_t;
161
167 virtual void set_on_disconnection_handler(const disconnection_handler_t& disconnection_handler) = 0;
168 };
169
170 } // namespace network
171
172 } // namespace cpp_redis
cpp_redis::network::tcp_client_iface::write_request::buffer
std::vector< char > buffer
Definition: tcp_client_iface.hpp:133
cpp_redis::network::tcp_client_iface::~tcp_client_iface
virtual ~tcp_client_iface(void)=default
dtor
cpp_redis::network::tcp_client_iface::is_connected
virtual bool is_connected(void) const =0
cpp_redis::network::tcp_client_iface::read_result::buffer
std::vector< char > buffer
Definition: tcp_client_iface.hpp:79
cpp_redis::network::tcp_client_iface::async_read
virtual void async_read(read_request &request)=0
cpp_redis::network::tcp_client_iface::read_request
Definition: tcp_client_iface.hpp:114
cpp_redis::network::tcp_client_iface::write_result
Definition: tcp_client_iface.hpp:85
cpp_redis::network::tcp_client_iface::connect
virtual void connect(const std::string &addr, std::uint32_t port, std::uint32_t timeout_msecs=0)=0
cpp_redis::network::tcp_client_iface::disconnection_handler_t
std::function< void()> disconnection_handler_t
Definition: tcp_client_iface.hpp:160
cpp_redis::network::tcp_client_iface::disconnect
virtual void disconnect(bool wait_for_removal=false)=0
cpp_redis::network::tcp_client_iface::async_write_callback_t
std::function< void(write_result &)> async_write_callback_t
Definition: tcp_client_iface.hpp:108
cpp_redis::network::tcp_client_iface::read_request::size
std::size_t size
Definition: tcp_client_iface.hpp:118
cpp_redis::network::tcp_client_iface::write_request::async_write_callback
async_write_callback_t async_write_callback
Definition: tcp_client_iface.hpp:138
cpp_redis::network::tcp_client_iface::async_write
virtual void async_write(write_request &request)=0
cpp_redis::network::tcp_client_iface::read_result::success
bool success
Definition: tcp_client_iface.hpp:74
cpp_redis::network::tcp_client_iface::async_read_callback_t
std::function< void(read_result &)> async_read_callback_t
Definition: tcp_client_iface.hpp:102
cpp_redis::network::tcp_client_iface::write_result::success
bool success
Definition: tcp_client_iface.hpp:89
cpp_redis::network::tcp_client_iface
Definition: tcp_client_iface.hpp:37
cpp_redis::network::tcp_client_iface::write_request
Definition: tcp_client_iface.hpp:129
cpp_redis::network::tcp_client_iface::set_on_disconnection_handler
virtual void set_on_disconnection_handler(const disconnection_handler_t &disconnection_handler)=0
cpp_redis::network::tcp_client_iface::read_request::async_read_callback
async_read_callback_t async_read_callback
Definition: tcp_client_iface.hpp:123
cpp_redis::network::tcp_client_iface::read_result
Definition: tcp_client_iface.hpp:70
cpp_redis::network::tcp_client_iface::write_result::size
std::size_t size
Definition: tcp_client_iface.hpp:94
cpp_redis::network::tcp_client_iface::tcp_client_iface
tcp_client_iface(void)=default
ctor
cpp_redis
Definition: array_builder.hpp:29