Skip to content

Commit b85a1db

Browse files
committed
Debugging added.
1 parent 8a76912 commit b85a1db

5 files changed

Lines changed: 91 additions & 16 deletions

File tree

‎scripts/build-and-test.sh‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ ENABLE_STATIC="ON"
1212
else
1313
ENABLE_STATIC="OFF"
1414
fi
15-
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_TESTS=ON -DENABLE_CI=ON -DENABLE_STATIC_LINKING=$ENABLE_STATIC
15+
16+
if [[ "$BUILD_TYPE" == "debug" ]]; then
17+
ENABLE_DEBUG="ON"
18+
else
19+
ENABLE_DEBUG="OFF"
20+
fi
21+
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_TESTS=ON -DENABLE_CI=ON -DENABLE_DEBUG=$ENABLE_DEBUG -DENABLE_STATIC_LINKING=$ENABLE_STATIC
1622

1723
make -j4
1824
ctest --output-on-failure --verbose

‎scripts/build.sh‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ ENABLE_STATIC="ON"
1212
else
1313
ENABLE_STATIC="OFF"
1414
fi
15-
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_TESTS=OFF -DENABLE_CI=ON -DENABLE_STATIC_LINKING=$ENABLE_STATIC
15+
16+
if [[ "$BUILD_TYPE" == "debug" ]]; then
17+
ENABLE_DEBUG="ON"
18+
else
19+
ENABLE_DEBUG="OFF"
20+
fi
21+
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DENABLE_TESTS=OFF -DENABLE_CI=ON -DENABLE_DEBUG=$ENABLE_DEBUG -DENABLE_STATIC_LINKING=$ENABLE_STATIC
1622

1723
make -j16
1824
make install

‎src/include/framework/tcp_connection.hpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

‎src/include/framework/tcp_handlers.hpp‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,14 @@ class tcp_handlers : public std::enable_shared_from_this<tcp_handlers> {
3636
read_handler_type on_read = nullptr,
3737
handler_type on_write = nullptr,
3838
handler_type on_disconnected = nullptr,
39-
error_handler_type on_error = nullptr)
40-
: on_connect_(std::move(on_connect)),
41-
on_accepted_(std::move(on_accepted)),
42-
on_read_(std::move(on_read)),
43-
on_write_(std::move(on_write)),
44-
on_disconnected_(std::move(on_disconnected)),
45-
on_error_(std::move(on_error)) {}
46-
47-
handler_type on_connect() const { return on_connect_; }
48-
handler_type on_accepted() const { return on_accepted_; }
49-
read_handler_type on_read() const { return on_read_; }
50-
handler_type on_write() const { return on_write_; }
51-
handler_type on_disconnected() const { return on_disconnected_; }
52-
error_handler_type on_error() const { return on_error_; }
39+
error_handler_type on_error = nullptr);
40+
41+
handler_type on_connect() const;
42+
handler_type on_accepted() const;
43+
read_handler_type on_read() const;
44+
handler_type on_write() const;
45+
handler_type on_disconnected() const;
46+
error_handler_type on_error() const;
5347

5448
private:
5549
handler_type on_connect_;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2025 Ian Torres <iantorres@outlook.com>
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License.
6+
//
7+
// This program is distributed in the hope that it will be useful,
8+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
// GNU Affero General Public License for more details.
11+
//
12+
// You should have received a copy of the GNU Affero General Public License
13+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
15+
#include <framework/tcp_handlers.hpp>
16+
17+
namespace framework {
18+
tcp_handlers::tcp_handlers(handler_type on_connect, handler_type on_accepted,
19+
read_handler_type on_read, handler_type on_write,
20+
handler_type on_disconnected,
21+
error_handler_type on_error)
22+
: on_connect_(std::move(on_connect)),
23+
on_accepted_(std::move(on_accepted)),
24+
on_read_(std::move(on_read)),
25+
on_write_(std::move(on_write)),
26+
on_disconnected_(std::move(on_disconnected)),
27+
on_error_(std::move(on_error)) {}
28+
29+
tcp_handlers::handler_type tcp_handlers::on_connect() const {
30+
return on_connect_;
31+
}
32+
33+
tcp_handlers::handler_type tcp_handlers::on_accepted() const {
34+
return on_accepted_;
35+
}
36+
37+
tcp_handlers::read_handler_type tcp_handlers::on_read() const {
38+
return on_read_;
39+
}
40+
41+
tcp_handlers::handler_type tcp_handlers::on_write() const { return on_write_; }
42+
43+
tcp_handlers::handler_type tcp_handlers::on_disconnected() const {
44+
return on_disconnected_;
45+
}
46+
47+
tcp_handlers::error_handler_type tcp_handlers::on_error() const {
48+
return on_error_;
49+
}
50+
} // namespace framework

0 commit comments

Comments
 (0)