A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/cpp-redis/cpp_redis/wiki/Custom-network-module below:

Custom network module · cpp-redis/cpp_redis Wiki · GitHub

tacopie is a C++11 TCP Client library used by default by cpp_redis to make it easy to test and develop a software communicating with a Redis server using cpp_redis.

However, tacopie might not fulfill the needs of everyone: some people already use another networking library for other features or are looking for some feature not supported by tacopie.

To solve this issue, tacopie is not a mandatory dependency but is only provided as-is for convenience. The developer is free to use any other networking library by following the steps listed above.

Only asynchronous TCP clients are supported. No support for synchronous clients is planned.

Setting-Up your custom library CMake USE_CUSTOM_TCP_CLIENT

First, you have to compile with the USE_CUSTOM_TCP_CLIENT CMake variable. This CMake variable will make cpp_redis compile in a special configuration allowing you to use the library of your choice.

Provide implementation for tcp_client_iface

cpp_redis defines the tcp_client_iface interface in cpp_redis/network/tcp_client_iface.hpp.

You must provide an implementation for this interface by creating your own class inheriting from cpp_redis::network::tcp_client_iface and implementing the following methods:

Full documentation on Doxygen

virtual void connect(const std::string& addr, std::uint32_t port) = 0;

Connect the TCP client to the given host and port.

virtual void disconnect(bool wait_for_removal = false) = 0;

Disconnect the TCP client.

If wait_for_removal is set to true, disconnect blocks until the underlying TCP client has been effectively removed from the io_service (if any) and that all the underlying callbacks have completed.

virtual bool is_connected(void) const = 0;

Returns whether the client is connected or not.

virtual void async_read(read_request& request)   = 0;

Takes as parameter a read_request and process a read operation asynchronously.

read_request is defined as follows:

//! structure to store read requests information
struct read_request {
  std::size_t size;
  async_read_callback_t async_read_callback;
};

where:

async_read_callback is defined as follow:

typedef std::function<void(read_result&)> async_read_callback_t;

where read_result is defined as follows:

//! structure to store read requests results
struct read_result {
  bool success;
  std::vector<char> buffer;
};

where:

virtual void async_write(write_request& request) = 0;

Takes as parameter a write_request and process a write operation asynchronously.

write_request is defined as follows:

//! structure to store write requests information
struct write_request {
  std::vector<char> buffer;
  async_write_callback_t async_write_callback;
};

where:

async_write_callback is defined as follow:

typedef std::function<void(write_result&)> async_write_callback_t;

where write_result is defined as follows:

//! structure to store write requests results
struct write_result {
  bool success;
  std::size_t size;
};

where:

Use your custom TCP client with cpp_redis

The last step is to simply use the tcp_client you just have just created with cpp_redis.

When compiling with USE_CUSTOM_TCP_CLIENT, the default constructors of redis_client, redis_subscriber, future_client are disabled and you must you another constructor instead:

explicit client(const std::shared_ptr<network::tcp_client_iface>& tcp_client);
explicit subscriber(const std::shared_ptr<network::tcp_client_iface>& tcp_client);
explicit sentinel(const std::shared_ptr<network::tcp_client_iface>& tcp_client);

Each of these constructors simply takes a shared_ptr to a tcp_client_iface to be initialized: simply pass in a shared_ptr to your custom TCP client.

That's it, you are all set and can start using cpp_redis with your chosen TCP client library!


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4