Esempio n. 1
0
AVHTTP_DECL std::size_t read_body(AsyncReadStream& stream,
	const avhttp::url& url, MutableBufferSequence& buffers, boost::system::error_code &ec)
{
	std::size_t readed = 0;
	stream.open(url, ec);
	if (ec)
		return -1;
	readed = boost::asio::read(stream, buffers, transfer_response_body(stream.content_length()), ec);

	if(ec == boost::asio::error::eof && stream.content_length() == -1)
		ec = boost::system::error_code();
	return readed;
}
Esempio n. 2
0
 future<size_t> read_some(AsyncReadStream& s, const std::shared_ptr<char>& buffer, size_t length, size_t offset)
 {
   promise<size_t>::ptr completion_promise(new promise<size_t>("fc::asio::async_read_some"));
   s.async_read_some(boost::asio::buffer(buffer.get() + offset, length), 
                     detail::read_write_handler_with_buffer(completion_promise, buffer));
   return completion_promise;//->wait();
 }
Esempio n. 3
0
 future<size_t> read_some(AsyncReadStream& s, char* buffer, size_t length, size_t offset = 0)
 {
   promise<size_t>::ptr completion_promise(new promise<size_t>("fc::asio::async_read_some"));
   s.async_read_some(boost::asio::buffer(buffer + offset, length), 
                     detail::read_write_handler(completion_promise));
   return completion_promise;//->wait();
 }
Esempio n. 4
0
    size_t read_some( AsyncReadStream& s, const MutableBufferSequence& buf ) {
        detail::non_blocking<AsyncReadStream> non_blocking;

        // TODO: determine if non_blocking query results in a system call that
        // will slow down every read... 
        if( non_blocking(s) || non_blocking(s,true) ) {
            boost::system::error_code ec;
            size_t r = s.read_some( buf, ec );
            if( !ec ) return r;
            if( ec != boost::asio::error::would_block ) 
                  BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
        }
        
        promise<size_t>::ptr p(new promise<size_t>("fc::asio::read_some"));
        s.async_read_some( buf, boost::bind( detail::read_write_handler, p, _1, _2 ) );
        return p->wait();
    }
Esempio n. 5
0
 void async_read(AsyncReadStream & stream, std::size_t read_size, ReadHandler handler)
 {
     if(!lock_read(stream, handler)) return;
     
     if(read_size < m_buffer.size())
     {
         stream.get_io_service().post(std::bind(&read_stream_buffer<StreamBufferClass, PodType>::template read_complete<ReadHandler>, 
            this, read_size, read_size, std::error_code(), 0, handler));
         return;
     }
     
     asio::async_read(stream, m_buffer, asio::transfer_at_least(
         read_size - m_buffer.size()), 
         std::bind(&read_stream_buffer::template read_complete<ReadHandler>, this, 
         m_buffer.size(), read_size, std::placeholders::_1, std::placeholders::_2, handler));
 }
Esempio n. 6
0
 void async_read_some(AsyncReadStream& s, const std::shared_ptr<char>& buffer,
                      size_t length, size_t offset, promise<size_t>::ptr completion_promise)
 {
   s.async_read_some(boost::asio::buffer(buffer.get() + offset, length), detail::read_write_handler_with_buffer(completion_promise, buffer));
 }
Esempio n. 7
0
 void async_read_some(AsyncReadStream& s, char* buffer,
                      size_t length, promise<size_t>::ptr completion_promise)
 {
   s.async_read_some(boost::asio::buffer(buffer, length), detail::read_write_handler(completion_promise));
 }
Esempio n. 8
0
 void async_read_some(AsyncReadStream& s, const MutableBufferSequence& buf, promise<size_t>::ptr completion_promise)
 {
   s.async_read_some(buf, detail::read_write_handler(completion_promise));
 }
Esempio n. 9
0
 future<size_t> read_some(AsyncReadStream& s, const MutableBufferSequence& buf)
 {
   promise<size_t>::ptr completion_promise(new promise<size_t>("fc::asio::async_read_some"));
   s.async_read_some(buf, detail::read_write_handler(completion_promise));
   return completion_promise;//->wait();
 }