Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] async_read and 100% CPU
From: Zachary Turner (divisortheory_at_[hidden])
Date: 2009-06-30 14:55:58


On Tue, Jun 30, 2009 at 1:46 PM, Etienne Philip
Pretorius<icewolfhunter_at_[hidden]> wrote:
> Michael Caisse wrote:
>>
>> Hi Etienne -
>>
>> Etienne Philip Pretorius wrote:
>>>
>>> Hello list,
>>>
>>> Could someone please shed some light on this subject. It seems that me
>>> read handler keeps on being called even when there has been no data
>>> transferred...
>>>
>>>            switch(error.value()) {
>>>                case boost::system::posix_error::success: {
>>>                    c = new client();
>>>
>>>                    socket.async_receive(
>>>                        boost::asio::buffer(
>>>                            buffer
>>>                        ),boost::bind(
>>>                            &client::handle_read,
>>>                            this,
>>>                            boost::asio::placeholders::error,
>>>                            boost::asio::placeholders::bytes_transferred
>>>                        )
>>>                    );
>>
>>
>> Try changing this to use socket.async_read_some instead of async_receive.
>>
>> Regards -
>> michael
>>
>>
> :D, just tried it - still no luck.
> I am invesigating if I am calling the buffer correctly. It seems that after
> the call to async_receive/async_read_some that there is still data pending
> for me to read... IE I never seem to get the data placed inside the
> std::vector correctly.

Are you saying that the handler is constantly getting called with
bytes_transferred = 0?

What is contained inside your buffer object? If your buffer has a
size of 0, then this seems like it would cause the problem.

Also, do you mean that for a single invocation of async_receive(), the
handler is getting called multiple times? Or that for each call to
async_receive, the handler gets called once with bytes_transferred=0?
Is there an error code?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net