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 
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
std::vector< char > buffer
Definition: tcp_client_iface.hpp:133
virtual ~tcp_client_iface(void)=default
dtor
virtual bool is_connected(void) const =0
std::vector< char > buffer
Definition: tcp_client_iface.hpp:79
virtual void async_read(read_request &request)=0
Definition: tcp_client_iface.hpp:114
Definition: tcp_client_iface.hpp:85
virtual void connect(const std::string &addr, std::uint32_t port, std::uint32_t timeout_msecs=0)=0
std::function< void()> disconnection_handler_t
Definition: tcp_client_iface.hpp:160
virtual void disconnect(bool wait_for_removal=false)=0
std::function< void(write_result &)> async_write_callback_t
Definition: tcp_client_iface.hpp:108
std::size_t size
Definition: tcp_client_iface.hpp:118
async_write_callback_t async_write_callback
Definition: tcp_client_iface.hpp:138
virtual void async_write(write_request &request)=0
bool success
Definition: tcp_client_iface.hpp:74
std::function< void(read_result &)> async_read_callback_t
Definition: tcp_client_iface.hpp:102
bool success
Definition: tcp_client_iface.hpp:89
Definition: tcp_client_iface.hpp:37
Definition: tcp_client_iface.hpp:129
virtual void set_on_disconnection_handler(const disconnection_handler_t &disconnection_handler)=0
async_read_callback_t async_read_callback
Definition: tcp_client_iface.hpp:123
Definition: tcp_client_iface.hpp:70
std::size_t size
Definition: tcp_client_iface.hpp:94
Definition: array_builder.hpp:29