Skip to content

IvanPinezhaninov/serveza

Repository files navigation

Serveza 🍺

The server you’d raise a glass to.

C++17 License Build


Overview

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.


Usage

  1. 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);
    }
  }
};
  1. 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();
}

License

This code is distributed under the MIT License

Author

Ivan Pinezhaninov

About

Small server library using Boost.Asio

Resources

License

Stars

Watchers

Forks