Skip to content

Commit

Permalink
The first step in adaptation for fmtlib-9.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
eao197 committed Jul 9, 2022
1 parent af7bdb1 commit 2d2e982
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 35 deletions.
25 changes: 16 additions & 9 deletions dev/restinio/impl/acceptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ class acceptor_t final
{
const auto ep = m_acceptor.local_endpoint();
m_logger.warn( [&]{
return fmt::format( "server already started on {}", ep );
return fmt::format( "server already started on {}",
fmtlib_tools::streamed( ep ) );
} );
return;
}
Expand All @@ -238,7 +239,8 @@ class acceptor_t final
try
{
m_logger.trace( [&]{
return fmt::format( "starting server on {}", ep );
return fmt::format( "starting server on {}",
fmtlib_tools::streamed( ep ) );
} );

m_acceptor.open( ep.protocol() );
Expand Down Expand Up @@ -272,7 +274,8 @@ class acceptor_t final
}

m_logger.info( [&]{
return fmt::format( "server started on {}", ep );
return fmt::format( "server started on {}",
fmtlib_tools::streamed( ep ) );
} );
}
catch( const std::exception & ex )
Expand All @@ -283,8 +286,8 @@ class acceptor_t final

m_logger.error( [&]() -> auto {
return fmt::format( "failed to start server on {}: {}",
ep,
ex.what() );
fmtlib_tools::streamed( ep ),
ex.what() );
} );

throw;
Expand Down Expand Up @@ -440,7 +443,8 @@ class acceptor_t final
m_logger.trace( [&]{
return fmt::format(
"accept connection from {} on socket #{}",
remote_endpoint, i );
fmtlib_tools::streamed( remote_endpoint ),
i );
} );

// Since v.0.5.1 the incoming connection must be
Expand All @@ -456,7 +460,8 @@ class acceptor_t final
return fmt::format(
"accepted connection from {} on socket #{} denied by"
" IP-blocker",
remote_endpoint, i );
fmtlib_tools::streamed( remote_endpoint ),
i );
} );
// incoming_socket will be closed automatically.
break;
Expand Down Expand Up @@ -526,13 +531,15 @@ class acceptor_t final
// for m_acceptor.
restinio::utils::log_trace_noexcept( m_logger,
[&]{
return fmt::format( "closing server on {}", ep );
return fmt::format( "closing server on {}",
fmtlib_tools::streamed( ep ) );
} );

m_acceptor.close();

m_logger.info( [&]{
return fmt::format( "server closed on {}", ep );
return fmt::format( "server closed on {}",
fmtlib_tools::streamed( ep ) );
} );
}

Expand Down
4 changes: 2 additions & 2 deletions dev/restinio/impl/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class connection_t final
return fmt::format(
"[connection:{}] start connection with {}",
connection_id(),
m_remote_endpoint );
fmtlib_tools::streamed( m_remote_endpoint ) );
} );
}

Expand Down Expand Up @@ -936,7 +936,7 @@ class connection_t final
"flags: {}, write group size: {}",
connection_id(),
request_id,
response_output_flags,
fmtlib_tools::streamed( response_output_flags ),
wg.items_count() );
} );

Expand Down
14 changes: 14 additions & 0 deletions dev/restinio/impl/include_fmtlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ runtime_format_string( const char * fmt_string )
}
#endif

#if FMT_VERSION < 90000
template< typename T >
decltype(auto) streamed( T && v ) noexcept
{
return std::forward<T>(v);
}
#else
template< typename T >
decltype(auto) streamed( T && v ) noexcept
{
return fmt::streamed( std::forward<T>(v) );
}
#endif

} /* namespace fmtlib_tools */

} /* namespace restinio */
Expand Down
2 changes: 1 addition & 1 deletion dev/restinio/websocket/impl/ws_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ws_connection_t final
return fmt::format(
"[ws_connection:{}] start connection with {}",
connection_id(),
m_socket.remote_endpoint() );
fmtlib_tools::streamed( m_socket.remote_endpoint() ) );
} );

// Inform state listener if it used.
Expand Down
4 changes: 2 additions & 2 deletions dev/sample/connection_state/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class connection_listener_t

fmt::print( "connection-notice: {} (from {}) => {}\n",
notice.connection_id(),
notice.remote_endpoint(),
restinio::fmtlib_tools::streamed( notice.remote_endpoint() ),
cause_to_str( notice ) );
}
};
Expand All @@ -51,7 +51,7 @@ restinio::request_handling_status_t handler( const restinio::request_handle_t& r
.append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" )
.set_body( fmt::format( "{} (from {}): Hello world!",
req->connection_id(),
req->remote_endpoint() ) )
restinio::fmtlib_tools::streamed( req->remote_endpoint() ) ) )
.done();

return restinio::request_accepted();
Expand Down
3 changes: 2 additions & 1 deletion dev/sample/hello_world_basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ restinio::request_handling_status_t handler( const restinio::request_handle_t& r
.append_header( restinio::http_field::server, "RESTinio hello world server" )
.append_header_date_field()
.append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" )
.set_body( fmt::format( "{}: Hello world!", req->remote_endpoint() ) )
.set_body( fmt::format( "{}: Hello world!",
restinio::fmtlib_tools::streamed( req->remote_endpoint() ) ) )
.done();

return restinio::request_accepted();
Expand Down
3 changes: 2 additions & 1 deletion dev/sample/run_existing_server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ restinio::request_handling_status_t handler( const restinio::request_handle_t& r
.append_header( restinio::http_field::server, "RESTinio hello world server" )
.append_header_date_field()
.append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" )
.set_body( fmt::format( "{}: Hello world!", req->remote_endpoint() ) )
.set_body( fmt::format( "{}: Hello world!",
restinio::fmtlib_tools::streamed( req->remote_endpoint() ) ) )
.done();

return restinio::request_accepted();
Expand Down
3 changes: 2 additions & 1 deletion dev/sample/run_for_minute/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ restinio::request_handling_status_t handler( const restinio::request_handle_t& r
.append_header( restinio::http_field::server, "RESTinio hello world server" )
.append_header_date_field()
.append_header( restinio::http_field::content_type, "text/plain; charset=utf-8" )
.set_body( fmt::format( "{}: Hello world!", req->remote_endpoint() ) )
.set_body( fmt::format( "{}: Hello world!",
restinio::fmtlib_tools::streamed( req->remote_endpoint() ) ) )
.done();

return restinio::request_accepted();
Expand Down
4 changes: 3 additions & 1 deletion dev/test/common/pub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ do_request(
sout << &response_stream;

if ( !restinio::error_is_eof( error ) )
throw std::runtime_error{ fmt::format( "read error: {}", error ) };
throw std::runtime_error{
fmt::format( "read error: {}",
restinio::fmtlib_tools::streamed( error ) ) };

result = sout.str();
},
Expand Down
24 changes: 18 additions & 6 deletions dev/test/handle_requests/connection_state/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ TEST_CASE( "ordinary connection" , "[ordinary_connection]" )
.connection_state_listener( state_listener )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -287,7 +289,9 @@ TEST_CASE( "connection state for WS" , "[connection_state][ws]" )
.connection_state_listener( state_listener )
.request_handler(
[&endpoint_value, &endpoint_value_ws]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

if( restinio::http_connection_header_t::upgrade == req->header().connection() )
{
Expand All @@ -302,7 +306,9 @@ TEST_CASE( "connection state for WS" , "[connection_state][ws]" )
rws::message_handle_t ){} );


endpoint_value_ws = fmt::format( "{}", ws->remote_endpoint() );
endpoint_value_ws = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
ws->remote_endpoint() ) );

ws->kill();

Expand Down Expand Up @@ -371,7 +377,9 @@ TEST_CASE( "listener throws on accept" , "[throws_on_accept]" )
.connection_state_listener( state_listener )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -431,7 +439,9 @@ TEST_CASE( "listener throws on close" , "[throws_on_close]" )
.connection_state_listener( state_listener )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -495,7 +505,9 @@ TEST_CASE( "listener throws on WS-upgrade" , "[throws_on_ws_upgrade]" )
.connection_state_listener( state_listener )
.request_handler(
[&endpoint_value, &ws_upgrade_failed]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

if( restinio::http_connection_header_t::upgrade == req->header().connection() )
{
Expand Down
12 changes: 9 additions & 3 deletions dev/test/handle_requests/remote_endpoint/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ TEST_CASE( "remote_endpoint extraction" , "[remote_endpoint]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -89,7 +91,9 @@ TEST_CASE( "remote_endpoint for WS" , "[remote_endpoint][ws]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value, &endpoint_value_ws]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

if( restinio::http_connection_header_t::upgrade == req->header().connection() )
{
Expand All @@ -104,7 +108,9 @@ TEST_CASE( "remote_endpoint for WS" , "[remote_endpoint][ws]" )
const rws::message_handle_t& ){} );


endpoint_value_ws = fmt::format( "{}", ws->remote_endpoint() );
endpoint_value_ws = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
ws->remote_endpoint() ) );

ws->kill();

Expand Down
4 changes: 3 additions & 1 deletion dev/test/handle_requests/user_data_simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ TEST_CASE( "remote_endpoint extraction" , "[remote_endpoint]" )
.extra_data_factory( extra_data_factory )
.request_handler(
[&endpoint_value, &index_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );
index_value = req->extra_data().m_index;

req->create_response()
Expand Down
24 changes: 18 additions & 6 deletions dev/test/run_on_thread_pool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ TEST_CASE( "on thread pool with break signals" , "[with_break_signal]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -127,7 +129,9 @@ TEST_CASE( "on thread pool without break signals" , "[without_break_signal]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -192,7 +196,9 @@ TEST_CASE( "server on thread pool runner" , "[on_pool_runner]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -254,7 +260,9 @@ TEST_CASE( "run_async with manual stop/wait" , "[run_async]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -303,7 +311,9 @@ TEST_CASE( "run_async with manual stop without wait" , "[run_async]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down Expand Up @@ -353,7 +363,9 @@ TEST_CASE( "run_async with automatic stop/wait" , "[run_async]" )
.address( "127.0.0.1" )
.request_handler(
[&endpoint_value]( auto req ){
endpoint_value = fmt::format( "{}", req->remote_endpoint() );
endpoint_value = fmt::format( "{}",
restinio::fmtlib_tools::streamed(
req->remote_endpoint() ) );

req->create_response()
.append_header( "Server", "RESTinio utest server" )
Expand Down
3 changes: 2 additions & 1 deletion externals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
end

MxxRu::arch_externals :fmt do |e|
e.url 'https://github.com/fmtlib/fmt/archive/8.1.1.zip'
e.url 'https://github.com/fmtlib/fmt/archive/9.0.0.zip'
# e.url 'https://github.com/fmtlib/fmt/archive/8.1.1.zip'
# e.url 'https://github.com/fmtlib/fmt/archive/7.1.3.zip'

e.map_dir 'include' => 'dev/fmt'
Expand Down

0 comments on commit 2d2e982

Please sign in to comment.