@@ -33,35 +33,54 @@ class tcp_connection : public std::enable_shared_from_this<tcp_connection> {
3333 shared_of<tcp_executor> get_strand () const noexcept ;
3434 shared_of<tcp_stream> get_stream () const noexcept ;
3535 async_of<void > notify_write ();
36+
3637 template <typename Buffer>
3738 void invoke (Buffer &&buf) {
39+ LOG (" tcp_connection::invoke() start id=" << id_);
40+
3841 auto _self = this ->shared_from_this ();
42+ LOG (" tcp_connection::invoke() shared_from_this acquired" );
43+
3944 co_spawn (
4045 *strand_,
4146 [_self, _buf = std::forward<Buffer>(buf)]() mutable -> async_of<void > {
47+ LOG (" tcp_connection::invoke() coroutine start id=" << _self->id_ );
48+
4249 auto _payload_buffer = boost::asio::buffer (_buf);
4350 const std::size_t _payload_size =
4451 boost::asio::buffer_size (_payload_buffer);
4552
53+ LOG (" invoke(): payload size = " << _payload_size);
54+
4655 if (_payload_size > MAX_FRAME_SIZE ) {
56+ LOG (" invoke(): ERROR payload too big: " << _payload_size);
4757 std::cerr << " Payload size is too big" << std::endl;
4858 co_return ;
4959 }
5060
5161 const auto _length = static_cast <std::uint32_t >(_payload_size);
62+ LOG (" invoke(): writing header with length=" << _length);
5263
5364 std::array<unsigned char , 4 > _header;
5465 _header[0 ] = static_cast <unsigned char >(_length >> 24 & 0xFF );
5566 _header[1 ] = static_cast <unsigned char >(_length >> 16 & 0xFF );
5667 _header[2 ] = static_cast <unsigned char >(_length >> 8 & 0xFF );
5768 _header[3 ] = static_cast <unsigned char >(_length >> 0 & 0xFF );
5869
70+ LOG (" invoke(): header created" );
71+
5972 std::array<boost::asio::const_buffer, 2 > _buffers{
6073 boost::asio::buffer (_header), _payload_buffer};
6174
75+ LOG (" invoke(): calling async_write() id=" << _self->id_ );
6276 co_await boost::asio::async_write (*_self->stream_ , _buffers,
6377 boost::asio::as_tuple);
78+ LOG (" invoke(): async_write() completed id=" << _self->id_ );
79+
80+ LOG (" invoke(): calling notify_write()" );
6481 co_await _self->notify_write ();
82+
83+ LOG (" invoke(): coroutine exit id=" << _self->id_ );
6584 co_return ;
6685 },
6786 boost::asio::detached);
0 commit comments