2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 04:42:09 +00:00

Fixes build for clang++-14,13,11.

This commit is contained in:
Marcelo Zimbres
2022-07-23 12:20:30 +02:00
parent 7bffa252f4
commit 0168ed5faf
8 changed files with 128 additions and 107 deletions

View File

@@ -17,13 +17,11 @@ check_PROGRAMS += intro
check_PROGRAMS += containers
check_PROGRAMS += serialization
check_PROGRAMS += test_low_level
if HAVE_CXX20
check_PROGRAMS += test_high_level
endif
EXTRA_PROGRAMS =
if HAVE_COROUTINES
EXTRA_PROGRAMS += subscriber
if HAVE_CXX20
EXTRA_PROGRAMS += echo_server
EXTRA_PROGRAMS += echo_server_direct
EXTRA_PROGRAMS += chat_room
@@ -37,13 +35,13 @@ CLEANFILES += $(EXTRA_PROGRAMS)
all: $(check_PROGRAMS) $(EXTRA_PROGRAMS)
intro_sync_SOURCES = $(top_srcdir)/tests/intro_sync.cpp
subscriber_SOURCES = $(top_srcdir)/examples/subscriber.cpp
test_low_level_SOURCES = $(top_srcdir)/tests/low_level.cpp
intro_SOURCES = $(top_srcdir)/examples/intro.cpp
containers_SOURCES = $(top_srcdir)/examples/containers.cpp
serialization_SOURCES = $(top_srcdir)/examples/serialization.cpp
if HAVE_CXX20
test_high_level_SOURCES = $(top_srcdir)/tests/high_level.cpp
if HAVE_COROUTINES
subscriber_SOURCES = $(top_srcdir)/examples/subscriber.cpp
chat_room_SOURCES = $(top_srcdir)/examples/chat_room.cpp
echo_server_SOURCES = $(top_srcdir)/examples/echo_server.cpp
echo_server_direct_SOURCES = $(top_srcdir)/benchmarks/cpp/asio/echo_server_direct.cpp

View File

@@ -396,7 +396,7 @@
- Boost 1.78 or greater.
- Unix Shell and Make (for linux users).
- C++14. Some examples require C++20 with coroutine support.
- C++17. Some examples require C++20 with coroutine support.
- Redis server.
Some examples will also require interaction with
@@ -406,8 +406,8 @@
Aedis has been tested with the following compilers
- Tested with gcc: 7.5.0, 8.4.0, 9.3.0, 10.3.0.
- Tested with clang: 11.0.0, 10.0.0, 9.0.1, 8.0.1, 7.0.1.
- Tested with gcc: 12, 11.
- Tested with clang: 14, 13, 11.
\section Installation

View File

@@ -8,13 +8,8 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/write.hpp>
#include <cstdio>
#include <boost/asio.hpp>
namespace net = boost::asio;
namespace this_coro = net::this_coro;

View File

@@ -1,9 +1,9 @@
AC_PREREQ([2.69])
AC_INIT([Aedis], [0.2.1], [mzimbres@gmail.com])
AC_CONFIG_MACRO_DIR([m4])
#AC_CONFIG_SRCDIR([src/aedis.cpp])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([-Wall foreign])
AC_LANG(C++)
# Checks for programs.
AC_PROG_CXX
@@ -18,10 +18,36 @@ AC_CHECK_HEADER_STDBOOL
AC_TYPE_UINT64_T
AC_CHECK_TYPES([ptrdiff_t])
AX_CXX_COMPILE_STDCXX(14, , mandatory)
AX_CXX_COMPILE_STDCXX(17, , mandatory)
AX_CXX_COMPILE_STDCXX(20, , optional)
AM_CONDITIONAL(HAVE_CXX20,[test x$HAVE_CXX20 == x1])
# This check has been stolen from Asio
AC_MSG_CHECKING([whether coroutines are enabled])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#if defined(__clang__)]]
[[# if (__cplusplus >= 201703) && (__cpp_coroutines >= 201703)]]
[[# if __has_include(<experimental/coroutine>)]]
[[# define AEDIS_HAS_CO_AWAIT 1]]
[[# endif]]
[[# endif]]
[[#elif defined(__GNUC__)]]
[[# if (__cplusplus >= 201709) && (__cpp_impl_coroutine >= 201902)]]
[[# if __has_include(<coroutine>)]]
[[# define AEDIS_HAS_CO_AWAIT 1]]
[[# endif]]
[[# endif]]
[[#endif]]
[[#ifndef AEDIS_HAS_CO_AWAIT]]
[[# error coroutines not available]]
[[#endif]])],
[AC_MSG_RESULT([yes])
HAVE_COROUTINES=yes;],
[AC_MSG_RESULT([no])
HAVE_COROUTINES=no;])
AM_CONDITIONAL(HAVE_COROUTINES,test x$HAVE_COROUTINES = xyes)
AC_CONFIG_FILES([Makefile doc/Doxyfile])
AC_OUTPUT

View File

@@ -6,7 +6,6 @@
#include <string>
#include <iostream>
#include <boost/asio.hpp>
#include <aedis/aedis.hpp>
#include <aedis/src.hpp>

View File

@@ -36,7 +36,6 @@ int main()
req.push("QUIT");
std::tuple<
aedis::ignore, // auth
aedis::ignore, // hello
aedis::ignore, // rpush
aedis::ignore, // hset
@@ -53,6 +52,6 @@ int main()
[](auto ec, auto) { std::cout << ec.message() << std::endl; });
ioc.run();
print(std::get<0>(std::get<7>(resp)).value());
print(std::get<1>(std::get<7>(resp)).value());
print(std::get<0>(std::get<6>(resp)).value());
print(std::get<1>(std::get<6>(resp)).value());
}

View File

@@ -4,9 +4,6 @@
* accompanying file LICENSE.txt)
*/
//#define BOOST_ASIO_HAS_IO_URING
//#define BOOST_ASIO_DISABLE_EPOLL
#include <string>
#include <iostream>
#include <boost/asio.hpp>

View File

@@ -4,7 +4,8 @@
* accompanying file LICENSE.txt)
*/
//#define BOOST_ASIO_ENABLE_HANDLER_TRACKING
// TODO: Avoid usage of co_await to improve tests is compilers that
// don't support it.
#include <iostream>
#include <boost/asio.hpp>
@@ -110,88 +111,6 @@ void test_quit()
test_quit2(cfg);
}
//----------------------------------------------------------------
net::awaitable<void>
push_consumer1(std::shared_ptr<connection> db, bool& received, char const* msg)
{
{
auto [ec, n] = co_await db->async_read_push(aedis::adapt(), as_tuple(net::use_awaitable));
expect_no_error(ec, msg);
received = true;
}
{
auto [ec, n] = co_await db->async_read_push(aedis::adapt(), as_tuple(net::use_awaitable));
expect_error(ec, boost::asio::experimental::channel_errc::channel_cancelled, msg);
}
}
void test_push_is_received1(connection::config const& cfg)
{
net::io_context ioc;
auto db = std::make_shared<connection>(ioc, cfg);
request req;
req.push("HELLO", 3);
req.push("SUBSCRIBE", "channel");
req.push("QUIT");
db->async_exec("127.0.0.1", "6379", req, aedis::adapt(), [](auto ec, auto r){
expect_error(ec, net::error::misc_errors::eof, "test_push_is_received1");
});
bool received = false;
net::co_spawn(
ioc.get_executor(),
push_consumer1(db, received, "test_push_is_received1"),
net::detached);
ioc.run();
expect_true(received);
}
//----------------------------------------------------------------
net::awaitable<void> run5(std::shared_ptr<connection> db)
{
{
request req;
req.push("QUIT");
db->async_exec(req, aedis::adapt(), [](auto ec, auto n){
expect_no_error(ec, "test_reconnect");
});
auto [ec] = co_await db->async_run("127.0.0.1", "6379", as_tuple(net::use_awaitable));
expect_error(ec, net::error::misc_errors::eof, "run5a");
}
{
request req;
req.push("QUIT");
db->async_exec(req, aedis::adapt(), [](auto ec, auto n){
expect_no_error(ec, "test_reconnect");
});
auto [ec] = co_await db->async_run("127.0.0.1", "6379", as_tuple(net::use_awaitable));
expect_error(ec, net::error::misc_errors::eof, "run5a");
}
co_return;
}
// Test whether the client works after a reconnect.
void test_reconnect()
{
net::io_context ioc;
auto db = std::make_shared<connection>(ioc.get_executor());
net::co_spawn(ioc, run5(db), net::detached);
ioc.run();
std::cout << "Success: test_reconnect()" << std::endl;
}
// Checks whether we get idle timeout when no push reader is set.
void test_missing_push_reader1(connection::config const& cfg)
{
@@ -267,6 +186,47 @@ void test_idle()
ioc.run();
}
#ifdef BOOST_ASIO_HAS_CO_AWAIT
net::awaitable<void>
push_consumer1(std::shared_ptr<connection> db, bool& received, char const* msg)
{
{
auto [ec, n] = co_await db->async_read_push(aedis::adapt(), as_tuple(net::use_awaitable));
expect_no_error(ec, msg);
received = true;
}
{
auto [ec, n] = co_await db->async_read_push(aedis::adapt(), as_tuple(net::use_awaitable));
expect_error(ec, boost::asio::experimental::channel_errc::channel_cancelled, msg);
}
}
void test_push_is_received1(connection::config const& cfg)
{
net::io_context ioc;
auto db = std::make_shared<connection>(ioc, cfg);
request req;
req.push("HELLO", 3);
req.push("SUBSCRIBE", "channel");
req.push("QUIT");
db->async_exec("127.0.0.1", "6379", req, aedis::adapt(), [](auto ec, auto r){
expect_error(ec, net::error::misc_errors::eof, "test_push_is_received1");
});
bool received = false;
net::co_spawn(
ioc.get_executor(),
push_consumer1(db, received, "test_push_is_received1"),
net::detached);
ioc.run();
expect_true(received);
}
void test_push_is_received2(connection::config const& cfg)
{
request req1;
@@ -305,6 +265,44 @@ void test_push_is_received2(connection::config const& cfg)
expect_true(received);
}
net::awaitable<void> run5(std::shared_ptr<connection> db)
{
{
request req;
req.push("QUIT");
db->async_exec(req, aedis::adapt(), [](auto ec, auto n){
expect_no_error(ec, "test_reconnect");
});
auto [ec] = co_await db->async_run("127.0.0.1", "6379", as_tuple(net::use_awaitable));
expect_error(ec, net::error::misc_errors::eof, "run5a");
}
{
request req;
req.push("QUIT");
db->async_exec(req, aedis::adapt(), [](auto ec, auto n){
expect_no_error(ec, "test_reconnect");
});
auto [ec] = co_await db->async_run("127.0.0.1", "6379", as_tuple(net::use_awaitable));
expect_error(ec, net::error::misc_errors::eof, "run5a");
}
co_return;
}
// Test whether the client works after a reconnect.
void test_reconnect()
{
net::io_context ioc;
auto db = std::make_shared<connection>(ioc.get_executor());
net::co_spawn(ioc, run5(db), net::detached);
ioc.run();
std::cout << "Success: test_reconnect()" << std::endl;
}
net::awaitable<void>
push_consumer3(std::shared_ptr<connection> db)
{
@@ -355,32 +353,41 @@ void test_push_many_subscribes(connection::config const& cfg)
ioc.run();
}
#endif
void test_push()
{
connection::config cfg;
cfg.coalesce_requests = true;
#ifdef BOOST_ASIO_HAS_CO_AWAIT
test_push_is_received1(cfg);
test_push_is_received2(cfg);
test_push_many_subscribes(cfg);
#endif
test_missing_push_reader1(cfg);
test_missing_push_reader3(cfg);
cfg.coalesce_requests = false;
#ifdef BOOST_ASIO_HAS_CO_AWAIT
test_push_is_received1(cfg);
test_push_is_received2(cfg);
test_push_many_subscribes(cfg);
#endif
test_missing_push_reader2(cfg);
test_missing_push_reader3(cfg);
}
int main()
{
test_resolve();
test_connect();
test_quit();
test_push();
#ifdef BOOST_ASIO_HAS_CO_AWAIT
test_reconnect();
#endif
// Must come last as it sends a client pause.
test_idle();