Skip to content

sgns::api::Session

rpc session

#include <session.hpp>

Inherited by sgns::api::HttpSession, sgns::api::WsSession

Public Types

Name
using RpcContext Context
using boost::asio::ip::tcp::socket Socket
using boost::system::error_code ErrorCode
using boost::asio::streambuf Streambuf
using boost::asio::steady_timer Timer
using boost::signals2::connection Connection
using Timer::duration Duration
using uint64_t SessionId
using std::function< void(SessionId, SessionType)> OnCloseHandler
Event handlers.

Public Functions

Name
virtual ~Session() =default
virtual void start() =0
starts listening on socket
virtual Socket & socket() =0
void connectOnRequest(std::function< OnRequestSignature > callback)
connects on request callback
void connectOnCloseHandler(OnCloseHandler && handler)
connects on close callback
void processRequest(std::string_view request, std::shared_ptr< Session > session)
process request message
virtual void respond(std::string_view message) =0
send response message
void notifyOnClose(SessionId id, SessionType type)
makes on close notification to listener
virtual SessionId id() const =0
method to get id of the session
virtual SessionType type() const =0
method to get type of the session

Public Types Documentation

using Context

using sgns::api::Session::Context = RpcContext;

using Socket

using sgns::api::Session::Socket = boost::asio::ip::tcp::socket;

using ErrorCode

using sgns::api::Session::ErrorCode = boost::system::error_code;

using Streambuf

using sgns::api::Session::Streambuf = boost::asio::streambuf;

using Timer

using sgns::api::Session::Timer = boost::asio::steady_timer;

using Connection

using sgns::api::Session::Connection = boost::signals2::connection;

using Duration

using sgns::api::Session::Duration = Timer::duration;

using SessionId

using sgns::api::Session::SessionId = uint64_t;

using OnCloseHandler

using sgns::api::Session::OnCloseHandler = std::function<void(SessionId, SessionType)>;

Event handlers.

Public Functions Documentation

function ~Session

virtual ~Session() =default

function start

virtual void start() =0

starts listening on socket

Reimplemented by: sgns::api::HttpSession::start, sgns::api::WsSession::start

function socket

virtual Socket & socket() =0

Reimplemented by: sgns::api::HttpSession::socket, sgns::api::WsSession::socket

function connectOnRequest

inline void connectOnRequest(
    std::function< OnRequestSignature > callback
)

connects on request callback

Parameters:

  • callback on request callback

function connectOnCloseHandler

inline void connectOnCloseHandler(
    OnCloseHandler && handler
)

connects on close callback

Parameters:

  • handler on close event handler

function processRequest

inline void processRequest(
    std::string_view request,
    std::shared_ptr< Session > session
)

process request message

Parameters:

  • request message to process
  • session session instance

function respond

virtual void respond(
    std::string_view message
) =0

send response message

Parameters:

Reimplemented by: sgns::api::HttpSession::respond, sgns::api::WsSession::respond

function notifyOnClose

inline void notifyOnClose(
    SessionId id,
    SessionType type
)

makes on close notification to listener

Parameters:

  • id session id
  • type type of the closed session

function id

virtual SessionId id() const =0

method to get id of the session

Return: id of the session

Reimplemented by: sgns::api::HttpSession::id, sgns::api::WsSession::id

function type

virtual SessionType type() const =0

method to get type of the session

Return: type of the session

Reimplemented by: sgns::api::HttpSession::type, sgns::api::WsSession::type


Updated on 2026-03-04 at 13:10:43 -0800