@@ -31,7 +31,7 @@ void StcpConnection::start_read(shared_ptr_<Connection> &&connection) {
31
31
}
32
32
_socket->async_read_some (
33
33
boost::asio::buffer (&buffer[partial_size], buffer.size () - partial_size),
34
- [this , connection = std::move (connection), partial_size](
34
+ [ this , connection = std::move (connection), partial_size ](
35
35
const boost::system ::error_code &err, size_t transferred) mutable {
36
36
read_loop_ (std::move (connection), partial_size, err, transferred);
37
37
});
@@ -60,16 +60,21 @@ void StcpConnection::WriteBuffer::add(const Message &message, int32_t rid,
60
60
size += message.size ();
61
61
}
62
62
void StcpConnection::WriteBuffer::write (WriteHandler &&callback) {
63
- std::lock_guard<std::mutex> write_lock (connection.mutex );
64
- boost::asio::async_write (
65
- *connection._socket ,
66
- boost::asio::buffer (connection._write_buffer .data (), size),
67
- [callback = std::move (callback)](const boost::system ::error_code &error,
68
- size_t bytes_transferred) {
69
- DSA_REF_GUARD;
63
+ connection.socket ().get_io_context ().post ([
64
+ size = size, conn_ptr = connection.share_this <StcpConnection>(),
65
+ callback = std::move (callback)
66
+ ]() {
67
+ std::lock_guard<std::mutex> write_lock (conn_ptr->mutex );
68
+ boost::asio::async_write (
69
+ *conn_ptr->_socket ,
70
+ boost::asio::buffer (conn_ptr->_write_buffer .data (), size),
71
+ [callback = std::move (callback)](const boost::system ::error_code &error,
72
+ size_t bytes_transferred) {
73
+ DSA_REF_GUARD;
70
74
71
- callback (error);
72
- });
75
+ callback (error);
76
+ });
77
+ });
73
78
}
74
79
75
80
ssl_socket::lowest_layer_type &StcpConnection::socket () {
0 commit comments