inline int getladdrs(socket_type s, socket_addr_type** addrs,
    boost::system::error_code& ec)
{
  ec.clear();
  int result = error_wrapper(call_getladdrs(
        &msghdr::msg_namelen, s, addrs), ec);
#if defined(BOOST_WINDOWS)
  if (result == 0)
    ec.clear();
#endif
  return result;
}
inline int bind_remove(socket_type s, const socket_addr_type* addr,
    std::size_t addrlen, boost::system::error_code& ec)
{
  ec.clear();
  int result = error_wrapper(call_bind_remove(
        &msghdr::msg_namelen, s, addr, addrlen), ec);
#if defined(BOOST_WINDOWS)
  if (result == 0)
    ec.clear();
#endif
  return result;
}
Example #3
0
 inline boost::filesystem::path symbol_location(const T& symbol, boost::system::error_code& ec) {
     ec.clear();
     return boost::dll::symbol_location_ptr(
         boost::dll::detail::aggressive_ptr_cast<const void*>(boost::addressof(symbol)),
         ec
     );
 }
Example #4
0
 size_t DropSink::write(
     Sample const & sample, 
     boost::system::error_code & ec)
 {
     ec.clear();
     return sample.size;
 }
Example #5
0
std::size_t message::write(std::ostream& out,
    boost::system::error_code& ec, bool headers_only)
{
    // reset error_code
    ec.clear();

    // initialize write buffers for send operation using HTTP headers
    write_buffers_t write_buffers;
    prepare_buffers_for_send(write_buffers, true, false);

    // append payload content to write buffers (if there is any)
    if (!headers_only && get_content_length() > 0 && get_content() != NULL)
        write_buffers.push_back(boost::asio::buffer(get_content(), get_content_length()));

    // write message to the output stream
    std::size_t bytes_out = 0;
    for (write_buffers_t::const_iterator i=write_buffers.begin(); i!=write_buffers.end(); ++i) {
        const char *ptr = boost::asio::buffer_cast<const char*>(*i);
        size_t len = boost::asio::buffer_size(*i);
        out.write(ptr, len);
        bytes_out += len;
    }

    return bytes_out;
}
Example #6
0
 bool PptvMedia::get_basic_info(
     ppbox::data::MediaBasicInfo & info, 
     boost::system::error_code & ec) const
 {
     info = parsed_video_;
     ec.clear();
     return true;
 }
Example #7
0
 bool PptvMedia::get_url(
     framework::string::Url & url,
     boost::system::error_code & ec) const
 {
     url = url_;
     ec.clear();
     return true;
 }
Example #8
0
 void MergeDispatcher::do_get_stream_status(
     StreamStatus & info, 
     boost::system::error_code & ec)
 {
     LOG_DEBUG("[do_get_stream_status]");
     merger_->stream_status(info);
     ec.clear();
 }
Example #9
0
 boost::system::error_code Connector::close(
     boost::system::error_code & ec)
 {
     started_ = false;
     ec.clear();
     canceled_ = false;
     return ec;
 }
	std::size_t high_resolution_timer::expires_at(const high_resolution_timer::time_type& expiry_time, boost::system::error_code& ec)
	{
		ec.clear();
		std::size_t ret = cancel(ec);
		m_expiration_time = expiry_time;
		m_expired = false;
		m_io_service.add_timer(this);
		return ret;
	}
Example #11
0
 bool MergeDispatcher::get_media_info(
     MediaInfo & info, 
     boost::system::error_code & ec)
 {
     LOG_DEBUG("[get_media_info]");
     merger_->media_info(info);
     ec.clear();
     return true;
 }
Example #12
0
 bool MergeDispatcher::get_stream_info(
     std::vector<StreamInfo> & streams, 
     boost::system::error_code & ec)
 {
     LOG_DEBUG("[get_stream_info]");
     merger_->stream_info(streams);
     ec.clear();
     return true;
 }
Example #13
0
 void MergeDispatcher::do_setup(
     boost::uint32_t index, 
     boost::system::error_code & ec)
 {
     LOG_DEBUG("[do_setup]");
     //muxer_->setup(index, ec);
     assert(index == (boost::uint32_t)-1);
     ec.clear();
 }
Example #14
0
inline pipe create_pipe(boost::system::error_code &ec)
{
    HANDLE handles[2];
    if (!::CreatePipe(&handles[0], &handles[1], NULL, 0))
        BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
    else
        ec.clear();
    return make_pipe(handles[0], handles[1]);
}
	std::size_t high_resolution_timer::expires_from_now(const duration_type& expiry_time
		, boost::system::error_code& ec)
	{
		ec.clear();
		std::size_t ret = cancel(ec);
		m_expiration_time = chrono::high_resolution_clock::now() + expiry_time;
		m_expired = false;
		m_io_service.add_timer(this);
		return ret;
	}
	std::size_t high_resolution_timer::cancel(boost::system::error_code& ec)
	{
		ec.clear();
		if (m_expired) return 0;
		m_expired = true;
		m_io_service.remove_timer(this);
		if (!m_handler) return 0;
		fire(boost::asio::error::operation_aborted);
		return 1;
	}
Example #17
0
 bool PptvVod::get_url(
     framework::string::Url & url,
     boost::system::error_code & ec) const
 {
     url = url_;
     url.svc("80");
     url.param("w", "1");
     url.param("z", "1");
     url.param("key", get_key());
     ec.clear();
     return true;
 }
Example #18
0
 bool PptvMedia::get_info(
     ppbox::data::MediaInfo & info,
     boost::system::error_code & ec) const
 {
     info = *video_;
     if (info.type == ppbox::data::MediaInfo::live) {
         info.start_time = jump_->server_time.to_time_t();
         info.current = info.shift + (Time::now() - local_time_).total_milliseconds();
     }
     ec.clear();
     return true;
 }
Example #19
0
        bool MergerBase::read(
            Sample & sample,
            boost::system::error_code & ec)
        {
            buffer_->drop_to(read_.time_range.pos, ec);
            buffer_->prepare_some(ec);

            if (seek_pending_ && !byte_seek(read_.time_range.big_pos(), ec)) {
                //if (ec == boost::asio::error::would_block) {
                //    block_on();
                //}
                return false;
            }

            ec.clear();

            while (!ec) {
                if (read_.time_range.end > read_.time_range.pos) {
                    sample.time = read_.time_range.big_pos() / media_info_.bitrate;
                    sample.size = read_size_;
                    if (sample.size > read_.time_range.end - read_.time_range.pos)
                        sample.size = (size_t)(read_.time_range.end - read_.time_range.pos);
                    assert(sample.size > 0);
                    sample.data.clear();
                    if (buffer_->fetch(read_.time_range.pos, sample.size, false, sample.data, ec)) {
                        read_.time_range.pos += sample.size;
                        break;
                    }
                    if (ec == boost::asio::error::eof && read_.time_range.end == invalid_size) {
                        read_.time_range.end = buffer_->read_segment().byte_range.end;
                        ec.clear();
                    }
                } else {
                    buffer_->drop_all(read_.time_range.end, ec);
                    byte_seek(read_.time_range.big_end(), ec);
                }
            }

            return !ec;
        }
Example #20
0
inline DWORD wait_for_exit(const Process &p, boost::system::error_code &ec)
{
    DWORD exit_code;

    if (::WaitForSingleObject(p.process_handle(), INFINITE) == WAIT_FAILED)
        BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
    else if (!::GetExitCodeProcess(p.process_handle(), &exit_code))
        BOOST_PROCESS_RETURN_LAST_SYSTEM_ERROR(ec);
    else
        ec.clear();

    return exit_code;
}
    inline boost::filesystem::path program_location_impl(boost::system::error_code& ec) {
        int mib[4];
        mib[0] = CTL_KERN;
        mib[1] = KERN_PROC;
        mib[2] = KERN_PROC_PATHNAME;
        mib[3] = -1;
        char buf[10240];
        size_t cb = sizeof(buf);
        sysctl(mib, 4, buf, &cb, NULL, 0);

        ec.clear();
        return boost::filesystem::path(buf);
    }
Example #22
0
std::size_t message::read(std::istream& in,
                          boost::system::error_code& ec,
                          parser& http_parser)
{
    // make sure that we start out with an empty message & clear error_code
    clear();
    ec.clear();
    
    // parse data from file one byte at a time
    boost::tribool parse_result;
    char c;
    while (in) {
        in.read(&c, 1);
        if ( ! in ) {
            ec = make_error_code(boost::system::errc::io_error);
            break;
        }
        http_parser.set_read_buffer(&c, 1);
        parse_result = http_parser.parse(*this, ec);
        if (! boost::indeterminate(parse_result)) break;
    }

    if (boost::indeterminate(parse_result)) {
        if (http_parser.check_premature_eof(*this)) {
            // premature EOF encountered
            if (! ec)
                ec = make_error_code(boost::system::errc::io_error);
        } else {
            // EOF reached when content length unknown
            // assume it is the correct end of content
            // and everything is OK
            parse_result = true;
            ec.clear();
        }
    }
    
    return (http_parser.get_total_bytes_read());
}
Example #23
0
 bool MergeDispatcher::assign(
     framework::string::Url const & url, 
     boost::system::error_code & ec)
 {
     TaskDispatcher::assign(url, ec);
     std::string format = url.param(param_format);
     if (format_ != format) {
         ec = ppbox::merge::error::format_not_match;
     }
     if (!ec) {
         merger_->reset(ec);
         if (ec == boost::asio::error::would_block)
             ec.clear();
     }
     return !ec;
 }
Example #24
0
 bool PptvVod::segment_url(
     size_t segment, 
     framework::string::Url & url,
     boost::system::error_code & ec) const
 {
     if (segments_ && segment >= segments_->size()) {
         ec = logic_error::item_not_exist;
         return false;
     }
     url = url_;
     url.protocol("http");
     url.path("/" + format(segment) + url.path());
     url.param("key", get_key());
     ec.clear();
     return true;
 }
Example #25
0
    inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
        ec.clear();

        std::string s;
        std::ifstream ifs("/proc/self/exefile");
        std::getline(ifs, s);

        if (ifs.fail() || s.empty()) {
            ec = boost::system::error_code(
                boost::system::errc::bad_file_descriptor,
                boost::system::generic_category()
            );
        }

        return boost::filesystem::path(s);
    }
Example #26
0
    tcp_session_ptr tcp_connector::connect( FactoryFunc fact_func, int port, 
        std::string const& hostname, boost::system::error_code & ec, options_ptr opts)
    {
        address addr = address::from_string(hostname, ec);
        if (ec)
        {
            // hostname不是IP地址, 尝试当作域名解析
            ec.clear();
            tcp::resolver::query query(hostname, lexical_cast_def<std::string>(port));
            tcp::resolver rsl(m_ios);
            tcp::resolver::iterator resolver_it = rsl.resolve(query, ec);
            if (ec)
                return tcp_session_ptr();

            ec = error::host_not_found;
            socket_ptr pSock(new socket(m_ios));
            while (ec && tcp::resolver::iterator() != resolver_it)
            {
                tcp::endpoint endpoint = *resolver_it++;
                std::cout << endpoint << std::endl;
                boost::system::error_code close_ec;
                pSock->close(close_ec);
                if (close_ec)
                    pSock.reset(new socket(m_ios));
                pSock->connect(endpoint, ec);
            }

            boost::system::error_code remote_ec, local_ec;
            if (!ec && pSock->remote_endpoint(remote_ec) != pSock->local_endpoint(local_ec)
                && !remote_ec && !local_ec)
                return fact_func(pSock, session_initialized(session_id(), group_id(), opts));
            else
                return tcp_session_ptr();
        }

        // hostname是IP地址
        tcp::endpoint endpoint(addr, port);
        socket_ptr pSock(new socket(m_ios));
        pSock->connect(endpoint, ec);
        
        boost::system::error_code remote_ec, local_ec;
        if (!ec && pSock->remote_endpoint(remote_ec) != pSock->local_endpoint(local_ec)
            && !remote_ec && !local_ec)
            return fact_func(pSock, session_initialized(session_id(), group_id(), opts));
        else
            return tcp_session_ptr();
    }
Example #27
0
        boost::uint64_t MergerBase::get_buffer_time(
            boost::system::error_code & ec, 
            boost::system::error_code & ec_buf)
        {
            buffer_->prepare_some(ec);

            if (seek_pending_ && !byte_seek(read_.time_range.big_pos(), ec)) {
                //if (ec == boost::asio::error::would_block) {
                //    block_on();
                //}
                ec_buf = buffer_->last_error();
                return 0;
            }

            ec_buf = buffer_->last_error();
            ec.clear();
            return buffer_->in_avail() * media_info_.bitrate;
        }
Example #28
0
    boost::system::error_code
    close
        ( boost::system::error_code & failure )
    {
        // This socket no longer reads messages.
        if ( get_socket( local_endpoint() ) == this )
        {
            add_route_to_socket( local_endpoint(), nullptr );
            failure.clear();
        }
        else
            failure = make_error_code( boost::system::errc::not_connected );

        pending_reads_.clear();
        pending_writes_.clear();

        return failure;
    }
Example #29
0
 bool PptvVod::segment_info(
     size_t segment,
     ppbox::data::SegmentInfo & info,
     boost::system::error_code & ec) const
 {
     ec.clear();
     if (segments_ && segment < segments_->size()) {
         info.head_size = segments_->at(segment).head_length;
         info.size = segments_->at(segment).file_length;
         info.offset = segments_->at(segment).offset;
         info.duration = segments_->at(segment).duration;
     } else {
         info.head_size = boost::uint64_t(-1);
         info.size = boost::uint64_t(-1);
         info.offset = boost::uint64_t(-1);
         info.duration = boost::uint64_t(-1);
     }
     return true;
 }
Example #30
0
 bool DispatchDownloader::get_statictis(
     DownloadStatistic & stat,
     boost::system::error_code & ec)
 {
     if (!opened_) {
         stat.total_size = 0;
         stat.finish_size = 0;
         stat.speed = 0;
         ec.clear();
         return true;
     }
     ppbox::data::StreamStatus info;
     if (!dispatcher_->get_stream_status(info, ec))
         return false;
     stat.total_size = info.byte_range.end;
     stat.finish_size = info.byte_range.pos;
     stat.speed = calc_speed(info.byte_range.pos);
     return true;
 }