Jump to content
  • Advertisement
Sign in to follow this  

boost::asio::tcp::socket continuously receives empty packets

This topic is 2907 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

    std::string sBuffer = new std::string;

boost::asio::buffer(*sBuffer, this->m_sValid.length()),

In Gateway::Auth this code is called once more if some conditions aren't fulfilled. But always, std::string passed to Gateway::Auth is empty, and Gateway::Auth is called continuously - not only async_read_some returns immediately, but also read handler is called in same moment, without waiting for data to arrive. Am I doing something wrong or is that bug? Oh, even if I send something from other app, string passed to Auth is always empty.

Share this post

Link to post
Share on other sites
void Gateway::Auth(std::string *, Connection::Pointer)
where connection::pointer is shared_ptr. Connection::socket() returns socket and m_sValid is not empty std::string.

Share this post

Link to post
Share on other sites
I'm going to start to agree with Linus on his rants about C++. These samples say absolutely nothing about types or anything else useful regarding the code.

Regardless, purely by handwaiving, my guess would be that the instance of string examined by Auth is not the same instance that is filled by network read_some. ::buffer isn't supposed to make a copy, but it might have something to do with implicit copy being made due to const-ness or some such (can't seem to recall what *foo resolves to).

Why not pass string by reference (keeping a local instead of allocating with new), just like buffer expects it? And why pass it into Auth at all. It doesn't make much sense to have more than one pending read request, so just using class' own instance allocated as value should work. Or perhaps I'm just used to structuring code differently.

Or the problem is somewhere completely else.

m_sValid is not empty std::string.
Are you sure? What if you just set the value to over 9000 or leave it out completely.

Share this post

Link to post
Share on other sites
What about setting the size of sBuffer after creating it?
std::string * sBuffer = new std::string;
sBuffer->resize( this->m_sValid.length() );
If you look at the code in buffer.hpp:

inline const_buffers_1 buffer(const std::string& data,
std::size_t max_size_in_bytes)
return const_buffers_1(
data.size() < max_size_in_bytes
? data.size() : max_size_in_bytes
, detail::buffer_debug_check<std::string::const_iterator>(data.begin())

Your buffer would still be an empty buffer since the amount of space in the string is less than the max length you pass in.

Share this post

Link to post
Share on other sites
The string is empty. You are not meant to use the string's memory in that way. You should use c_str which gives you this hint since it is const. Use std::vector instead and make sure it has memory allocated.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!