[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    Re: [Boost-users] Hi all,
From:       Pavel Vazharov via Boost-users <boost-users () lists ! boost ! org>
Date:       2024-03-06 14:36:26
Message-ID: CAK9EM1-XRLzBRLteQ4JpGtDqze9x7f3fGwOkJETqkngjfTWM3Q () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

The most obvious error that I see is that you use `std::vector<char>
buffer_data(1024);`as local variables and then they are destroyed but you
continue to keep references to them via the boost::asio::buffer.
The latter will not keep the `std::vector`s alive.
You need to keep the std::vector as a member variable and only when you
call the asio functions use the `boost::asio::buffer` function.
Like
m_socketHandler->socket.async_read_some(boost::asio::buffer(m_buffer_data),
...

Where the m_buffer_data is a member variable of type `std::vector<char>`.

HTH,
Pavel.

[Attachment #5 (text/html)]

<div dir="ltr"><div><div><div><div><div><div>Hi,<br><br></div>The most obvious error 
that I see is that you use `std::vector&lt;char&gt; 
buffer_data(1024);`as local variables and then they are destroyed but 
you continue to keep references to them via the boost::asio::buffer.</div></div>The \
latter will not keep the `std::vector`s alive.<br></div>You  need to keep the \
std::vector as a member variable and only when you  call the asio functions use the \
`boost::asio::buffer` \
function.<br></div><div>Like<br>m_socketHandler-&gt;socket.async_read_some(boost::asio::buffer(m_buffer_data), \
...<br><br></div><div>Where the m_buffer_data is a member variable of type \
`std::vector&lt;char&gt;`.<br></div><div><br></div>HTH,<br></div>Pavel.</div>



_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
https://lists.boost.org/mailman/listinfo.cgi/boost-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic