qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::protocol::accept< _IO_, _Socket > Class Template Reference

Protocol for handling the acceptance of new network connections. More...

#include <accept.h>

Inheritance diagram for qb::io::protocol::accept< _IO_, _Socket >:
Collaboration diagram for qb::io::protocol::accept< _IO_, _Socket >:

Public Types

using message = _Socket
 Type alias for the socket type.

Public Member Functions

 accept ()=delete
 Default constructor is deleted as an I/O component reference is required.
 accept (_IO_ &io) noexcept
 Constructor with I/O reference.
std::size_t getMessageSize () noexcept final
 Checks if a new connection is available to be processed.
void onMessage (std::size_t) noexcept final
 Processes a newly accepted connection.
void reset () noexcept final
 Resets the protocol state.
Public Member Functions inherited from qb::io::async::IProtocol
virtual ~IProtocol ()=default
 Virtual destructor.
bool ok () const noexcept
 Checks if the protocol is in a valid operational state.
void not_ok () noexcept
 Marks the protocol as being in an invalid or non-operational state.
void set_should_flush (bool should_flush) noexcept
 Sets the flag indicating whether the protocol should flush the input buffer after processing a message.
bool should_flush () const noexcept
 Gets the flag indicating whether the protocol should flush the input buffer after processing a message.

Additional Inherited Members

Protected Member Functions inherited from qb::io::async::AProtocol< _IO_ >
 AProtocol ()=delete
 Default constructor is deleted to ensure an I/O component is always associated.
 AProtocol (_IO_ &io) noexcept
 Constructor that associates the protocol with an I/O component.
virtual ~AProtocol ()=default
 Virtual destructor.
Protected Attributes inherited from qb::io::async::AProtocol< _IO_ >
_IO_ & _io
 Reference to the I/O component instance that this protocol is associated with.

Detailed Description

template<typename _IO_, typename _Socket>
class qb::io::protocol::accept< _IO_, _Socket >

Protocol for handling the acceptance of new network connections.

This template class implements the AProtocol interface specifically for connection-accepting components (like qb::io::async::tcp::acceptor). Its primary role is to detect when a new connection has been successfully accepted by the underlying listener socket and to deliver the new connection's socket (as _Socket type) to the I/O component.

Template Parameters
_IO_The I/O component type that uses this protocol (typically an acceptor class). It must provide a getAccepted() method returning a reference to the newly accepted socket.
_SocketThe type of socket that represents the newly accepted connection (e.g., qb::io::tcp::socket).

Member Typedef Documentation

◆ message

template<typename _IO_, typename _Socket>
using qb::io::protocol::accept< _IO_, _Socket >::message = _Socket

Type alias for the socket type.

The type of message this protocol produces, which is the accepted socket itself.

Constructor & Destructor Documentation

◆ accept()

template<typename _IO_, typename _Socket>
qb::io::protocol::accept< _IO_, _Socket >::accept ( _IO_ & io)
inlinenoexcept

Constructor with I/O reference.

Parameters
ioReference to the I/O component (e.g., an acceptor) that will use this protocol.

Member Function Documentation

◆ getMessageSize()

template<typename _IO_, typename _Socket>
std::size_t qb::io::protocol::accept< _IO_, _Socket >::getMessageSize ( )
inlinefinalvirtualnoexcept

Checks if a new connection is available to be processed.

This method determines if a new connection has been accepted by checking if the socket obtained from this->_io.getAccepted() is currently open.

Returns
1 if a new, open connection is available, 0 otherwise. The return type std::size_t is used to conform to the AProtocol interface, but effectively it's a boolean check.

Implements qb::io::async::AProtocol< _IO_ >.

◆ onMessage()

template<typename _IO_, typename _Socket>
void qb::io::protocol::accept< _IO_, _Socket >::onMessage ( std::size_t )
inlinefinalvirtualnoexcept

Processes a newly accepted connection.

This method is called when getMessageSize() returns a non-zero value (i.e., an open socket was found). It then calls the I/O component's on() handler, passing the newly accepted socket (obtained via this->_io.getAccepted()) by moving it.

Parameters
sizeIgnored parameter (required by AProtocol interface, but its value is not used here as getMessageSize() for this protocol effectively returns a boolean status).

Implements qb::io::async::AProtocol< _IO_ >.

◆ reset()

template<typename _IO_, typename _Socket>
void qb::io::protocol::accept< _IO_, _Socket >::reset ( )
inlinefinalvirtualnoexcept

Resets the protocol state.

This protocol is stateless regarding message parsing (it only checks socket status), so this method is a no-op.

Implements qb::io::async::AProtocol< _IO_ >.