qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
handshake.h
Go to the documentation of this file.
1
24
25#ifndef QB_IO_ASYNC_PROTOCOL_HANDSHAKE_H
26#define QB_IO_ASYNC_PROTOCOL_HANDSHAKE_H
27#include <functional>
28#include "../async/protocol.h"
30namespace qb::io::protocol {
31
40template <typename _IO_>
41class handshake : public async::AProtocol<_IO_> {
42 bool _handshake_done = false;
43public:
48 using message = qb::io::async::event::handshake;
49
53 handshake() = delete;
54
59 handshake(_IO_ &io) noexcept
61 this->set_should_flush(false);
62 }
63
74 std::size_t
75 getMessageSize() noexcept final {
76 if (_handshake_done)
77 return 0;
78 return static_cast<size_t>(this->_io.transport().do_handshake());
79 }
80
90 void
91 onMessage(std::size_t /*size*/) noexcept final { // size is unused
92 _handshake_done = true;
93 this->_io.on(message{});
94 }
95
101 void
102 reset() noexcept final {
103 _handshake_done = false;
104 }
105};
106
107} // namespace qb::io::protocol
108
109#endif // QB_IO_ASYNC_PROTOCOL_HANDSHAKE_H
Handshake event for asynchronous input streams.
Abstract base class for I/O-component-aware protocols (CRTP).
Definition protocol.h:146
_IO_ & _io
Reference to the I/O component instance that this protocol is associated with.
Definition protocol.h:166
void set_should_flush(bool should_flush) noexcept
Sets the flag indicating whether the protocol should flush the input buffer after processing a messag...
Definition protocol.h:117
handshake(_IO_ &io) noexcept
Constructor with I/O reference.
Definition handshake.h:59
handshake()=delete
Default constructor is deleted as an I/O component reference is required.
qb::io::async::event::handshake message
Type alias for the handshake event.
Definition handshake.h:48
void onMessage(std::size_t) noexcept final
Triggers the handshake event.
Definition handshake.h:91
std::size_t getMessageSize() noexcept final
Checks if the handshake is done.
Definition handshake.h:75
void reset() noexcept final
Resets the protocol state.
Definition handshake.h:102
Protocol interfaces for message processing in the asynchronous IO framework.