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.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 <cpp_redis/misc/error.hpp>
26 #include <cpp_redis/network/tcp_client_iface.hpp>
27 
28 #include <tacopie/tacopie>
29 
30 namespace cpp_redis {
31 
32 namespace network {
33 
37 class tcp_client : public tcp_client_iface {
38 public:
40  tcp_client(void) = default;
42  ~tcp_client(void) = default;
43 
44 public:
52  void connect(const std::string& addr, std::uint32_t port, std::uint32_t timeout_msecs);
53 
59  void disconnect(bool wait_for_removal = false);
60 
64  bool is_connected(void) const;
65 
71  void set_nb_workers(std::size_t nb_threads);
72 
73 public:
79  void async_read(read_request& request);
80 
86  void async_write(write_request& request);
87 
88 public:
94  void set_on_disconnection_handler(const disconnection_handler_t& disconnection_handler);
95 
96 private:
100  tacopie::tcp_client m_client;
101 };
102 
108 void set_default_nb_workers(std::size_t nb_threads);
109 
110 } // namespace network
111 
112 } // namespace cpp_redis
~tcp_client(void)=default
dtor
void set_on_disconnection_handler(const disconnection_handler_t &disconnection_handler)
void disconnect(bool wait_for_removal=false)
void async_read(read_request &request)
Definition: tcp_client_iface.hpp:114
void async_write(write_request &request)
std::function< void()> disconnection_handler_t
Definition: tcp_client_iface.hpp:160
void connect(const std::string &addr, std::uint32_t port, std::uint32_t timeout_msecs)
Definition: tcp_client_iface.hpp:37
Definition: tcp_client_iface.hpp:129
void set_nb_workers(std::size_t nb_threads)
tcp_client(void)=default
ctor
Definition: tcp_client.hpp:37
Definition: array_builder.hpp:29