The server you’d raise a glass to.
Serveza is a lightweight asynchronous server framework built on Boost.Asio and written in modern C++. It focuses on predictable behavior, minimal overhead, and code clarity - making it suitable for both embedded and high-performance network services.
- Define Your Session Handler
#include <boost/asio.hpp>
#include <serveza/serveza.hpp>
namespace net = boost::asio;
namespace sys = boost::system;
class TcpEcho final : public serveza::session<net::ip::tcp> {
public:
void operator()(net::any_io_executor ex, net::ip::tcp::socket socket, net::yield_context yield,
const sys::error_code& ec) noexcept override
{
net::streambuf buf;
while (yield.cancelled() == net::cancellation_type::none) {
std::size_t n = socket.async_read_some(buf.prepare(1024), yield);
if (ec == net::error::operation_aborted) break;
buf.commit(n);
net::async_write(socket, buf.data(), yield);
if (ec == net::error::operation_aborted) break;
buf.consume(n);
}
}
};- Set Up the Server
#include <boost/asio.hpp>
#include <serveza/serveza.hpp>
namespace net = boost::asio;
int main()
{
serveza::server server;
auto listener = server.make_listener<TcpEcho>({net::ip::tcp::v4(), 54321});
listener->start();
server.start();
}This code is distributed under the MIT License