Skip to content

Commit

Permalink
feat: refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
shuai132 committed Jun 18, 2024
1 parent 4fe0cf4 commit e25bb51
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/asio_net/detail/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace detail {

struct message : private noncopyable {
message() = default;
explicit message(std::string msg) : length(msg.length()), body(std::move(msg)) {}
explicit message(std::string msg) : length((uint32_t)msg.length()), body(std::move(msg)) {}

void clear() {
length = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/asio_net/detail/tcp_channel_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class tcp_channel_t : private noncopyable {
typename socket_impl<T>::socket& socket_;
const tcp_config& config_;
detail::message read_msg_;
uint32_t send_buffer_now_ = 0;
size_t send_buffer_now_ = 0;
std::deque<std::string> write_msg_queue_;
};

Expand Down
6 changes: 3 additions & 3 deletions include/asio_net/serial_port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ class serial_port : detail::noncopyable {
// queue for asio::async_write
if (!from_queue && send_buffer_now_ != 0) {
ASIO_NET_LOGV("queue for asio::async_write");
send_buffer_now_ += msg.size();
send_buffer_now_ += (uint32_t)msg.size();
write_msg_queue_.emplace_back(std::move(msg));
return;
}
if (!from_queue) {
send_buffer_now_ += msg.size();
send_buffer_now_ += (uint32_t)msg.size();
}

auto keeper = std::make_unique<detail::message>(std::move(msg));
auto buffer = asio::buffer(keeper->body);
asio::async_write(serial_, buffer, [this, keeper = std::move(keeper)](const std::error_code& ec, std::size_t /*length*/) {
send_buffer_now_ -= keeper->body.size();
send_buffer_now_ -= (uint32_t)keeper->body.size();
if (ec) {
do_close();
}
Expand Down
2 changes: 1 addition & 1 deletion test/udp_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main() {
udp_client client(context);
udp_client::endpoint endpoint(asio::ip::address_v4::from_string("127.0.0.1"), PORT);
client.send_to("hello", endpoint, [&](const std::error_code& ec, std::size_t size) {
LOG("result: ec: %d, size: %lu", ec.value(), size);
LOG("result: ec: %d, size: %zu", ec.value(), size);
});
context.run();
return EXIT_SUCCESS;
Expand Down

0 comments on commit e25bb51

Please sign in to comment.