font_resource_factory::font_resource_factory(const ::std::string& family, 
	error_code& ec, ::std::experimental::io2d::font_slant fs, ::std::experimental::io2d::font_weight fw, const ::std::experimental::io2d::matrix_2d& fm, 
	const ::std::experimental::io2d::font_options& fo, const ::std::experimental::io2d::matrix_2d& sm) noexcept
	: _Family()
	, _Font_slant(fs)
	, _Font_weight(fw)
	, _Font_options(fo)
	, _Font_matrix(fm)
	, _Surface_matrix(sm) {
	auto font = cairo_toy_font_face_create(family.c_str(), _Font_slant_to_cairo_font_slant_t(fs), _Font_weight_to_cairo_font_weight_t(fw));
	unique_ptr<cairo_font_face_t, decltype(&cairo_font_face_destroy)> ff(font, &cairo_font_face_destroy);
	ec = _Cairo_status_t_to_std_error_code(cairo_font_face_status(font));
	if (static_cast<bool>(ec)) {
		return;
	}
	::std::string s;
	try {
		s = cairo_toy_font_face_get_family(font);
	}
	catch (const ::std::bad_alloc&) {
		ec = make_error_code(errc::not_enough_memory);
		return;
	}
	catch (const ::std::length_error&) {
		ec = make_error_code(errc::not_enough_memory);
		return;
	}
	_Family = move(s);
	ec.clear();
}
Example #2
0
	void on_piece_write(size_t l,error_code ec)
	{
		if (write_cnt_>MAX_PIECE)
			return;
		if (!ec)
		{
			cache_impl_->read_piece("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",write_cnt_++,
				boost::bind(&disk_cache_test::on_piece_read,this,_1,_2)
				);


			std::string dummy=boost::lexical_cast<std::string>(write_cnt_);
			safe_buffer buf;
			safe_buffer_io io(&buf);
			io.write(dummy.c_str(),dummy.length()+1);

			cache_impl_->write_piece("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",1024*1024,write_cnt_,buf,
				boost::bind(&disk_cache_test::on_piece_write,this,_1,_2)
				);
		}
		else
		{
			std::cout<<"on_piece_write, ec.message="<<ec.message()<<std::endl;
		}
	}
size_t XMLClient::bytesToRead(const error_code& error, size_t bytes_read) {
    size_t result = bytes_read;
    _timer->cancel();

    // Connection closed cleanly by peer
    // asio errors http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/reference/error__basic_errors.html 
    if (error == boost::asio::error::eof || boost::asio::error::connection_reset == error) {
        Disconnect();
        return 0;
    } else if (error == boost::asio::error::operation_aborted) {
        Globals::ErrorMessage(" In bytesToRead Timer expired error \n");
    } else if (error) {
        // This error stops asynchronous reads
        std::stringstream s;
        s << "unknown bytesToRead error = (" << error << ") " << error.message() << std::endl;
        Globals::ErrorMessage(s.str());
        return 0;
    }

    if (bytes_read > 0) {
        AppendBuffer(std::string(data_, data_ + bytes_read));
        if (_endtag == NonsenseTag()) {
            _endtag = FindLeadingElement(_current);
            if (_endtag.empty()) _endtag = NonsenseTag();
        }
        //BufferHandler(std::string(data_, data_+bytes_read), "</CRCLStatus>") ;
        BufferHandler(_endtag);
    }
    StartAyncRead();
    return result;
}
Example #4
0
static bool error(error_code ec, Twine path = Twine()) {
  if (ec) {
    error(ec.message(), path);
    return true;
  }
  return false;
}
Example #5
0
 ResolverIterator resolve(
     implementation_type & impl, 
     NetName const & name, 
     error_code & ec)
 {
     boost::mutex::scoped_lock lock(sync_data_->mtx);
     LOG_DEBUG("[resolve] (name = %1%)" 
         % name.to_string());
     resolve_no_block(impl, name, ec);
     if (ec == boost::asio::error::would_block) {
         while (impl->state == ResolveTask::waiting) {
             sync_data_->cond.wait(lock);
         }
         ec = impl->ec;
     }
     if (!ec) {
         LOG_DEBUG("[resolve] resolved (name = %1%, endpoints = %2%)" 
             % name.to_string() % format(impl->endpoints));
         return ResolverIterator(svc_, impl, impl->endpoints[0]);
     } else {
         LOG_WARN("[resolve] resolved (name = %1%, ec = %2%)" 
             % name.to_string() % ec.message());
         return ResolverIterator();
     }
 }
	void close(char const* fmt, error_code const& ec)
	{
		end_time = clock_type::now();
		char tmp[1024];
		std::snprintf(tmp, sizeof(tmp), fmt, ec.message().c_str());
		int time = int(total_milliseconds(end_time - start_time));
		if (time == 0) time = 1;
		float up = (boost::int64_t(blocks_sent) * 0x4000) / time / 1000.f;
		float down = (boost::int64_t(blocks_received) * 0x4000) / time / 1000.f;
		error_code e;

		char ep_str[200];
		address const& addr = s.local_endpoint(e).address();
#if TORRENT_USE_IPV6
		if (addr.is_v6())
			std::snprintf(ep_str, sizeof(ep_str), "[%s]:%d", addr.to_string(e).c_str()
				, s.local_endpoint(e).port());
		else
#endif
			std::snprintf(ep_str, sizeof(ep_str), "%s:%d", addr.to_string(e).c_str()
				, s.local_endpoint(e).port());
		std::printf("%s ep: %s sent: %d received: %d duration: %d ms up: %.1fMB/s down: %.1fMB/s\n"
			, tmp, ep_str, blocks_sent, blocks_received, time, up, down);
		if (seed) --num_seeds;
	}
void save_settings::save(error_code& ec) const
{
	// back-up current settings file as .bak before saving the new one
	std::string backup = m_settings_file + ".bak";
	bool has_settings = exists(m_settings_file);
	bool has_backup = exists(backup);

	if (has_settings && has_backup)
		remove(backup, ec);

	if (has_settings)
		rename(m_settings_file, backup, ec);

	ec.clear();

	entry sett;
	m_ses.save_state(sett);

	for (std::map<std::string, int>::const_iterator i = m_ints.begin()
		, end(m_ints.end()); i != end; ++i)
	{
		sett[i->first] = i->second;
	}

	for (std::map<std::string, std::string>::const_iterator i = m_strings.begin()
		, end(m_strings.end()); i != end; ++i)
	{
		sett[i->first] = i->second;
	}
	std::vector<char> buf;
	bencode(std::back_inserter(buf), sett);
	save_file(m_settings_file, buf, ec);
}
Example #8
0
void disk_engine::complete_io(aio_task *aio, error_code err, uint32_t bytes, int delay_milliseconds)
{
    if (err != ERR_OK) {
        dinfo("disk operation failure with code %s, err = %s, aio_task_id = %016" PRIx64,
              aio->spec().name.c_str(),
              err.to_string(),
              aio->id());
    }

    // batching
    if (aio->code() == LPC_AIO_BATCH_WRITE) {
        aio->enqueue(err, (size_t)bytes);
        aio->release_ref(); // added in process_write
    }

    // no batching
    else {
        auto df = (disk_file *)(aio->aio()->file_object);
        if (aio->aio()->type == AIO_Read) {
            auto wk = df->on_read_completed(aio, err, (size_t)bytes);
            if (wk) {
                _provider->aio(wk);
            }
        }

        // write
        else {
            uint32_t sz;
            auto wk = df->on_write_completed(aio, (void *)&sz, err, (size_t)bytes);
            if (wk) {
                process_write(wk, sz);
            }
        }
    }
}
void run_test(std::string const& url, int size, int status, int connected
	, boost::optional<error_code> ec, proxy_settings const& ps)
{
	reset_globals();

	std::cerr << " ===== TESTING: " << url << " =====" << std::endl;

	std::cerr << " expecting: size: " << size
		<< " status: " << status
		<< " connected: " << connected
		<< " error: " << (ec?ec->message():"no error") << std::endl;

	boost::shared_ptr<http_connection> h(new http_connection(ios, cq
		, &::http_handler, true, &::http_connect_handler));
	h->get(url, seconds(1), 0, &ps);
	ios.reset();
	error_code e;
	ios.run(e);

	std::cerr << "connect_handler_called: " << connect_handler_called << std::endl;
	std::cerr << "handler_called: " << handler_called << std::endl;
	std::cerr << "status: " << http_status << std::endl;
	std::cerr << "size: " << data_size << std::endl;
	std::cerr << "error_code: " << g_error_code.message() << std::endl;
	TEST_CHECK(connect_handler_called == connected);
	TEST_CHECK(handler_called == 1);	
	TEST_CHECK(data_size == size || size == -1);
	TEST_CHECK(!ec || g_error_code == *ec);
	TEST_CHECK(http_status == status || status == -1);
}
Example #10
0
///  @brief If ec is not success, print the error and return true.
static bool error(error_code ec) {
    if (!ec) return false;

    outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
    outs().flush();
    return true;
}
Example #11
0
void daemon_s_service::on_update_configuration_on_meta_server_reply(
    ::dsn::replication::config_type::type type, std::shared_ptr<app_internal> &&  app,
    error_code err, dsn_message_t request, dsn_message_t response
)
{
    if (false == _online)
    {
        err.end_tracking();
        return;
    }

    configuration_update_response resp;
    if (err == ERR_OK)
    {
        ::dsn::unmarshall(response, resp);
        err = resp.err;
    }
    else if (err == ERR_TIMEOUT)
    {
        rpc::call(
            _fd->get_servers(),
            request,
            this,
            [=, cap_app = std::move(app)](error_code err, dsn_message_t reqmsg, dsn_message_t response) mutable
        {
            on_update_configuration_on_meta_server_reply(type, std::move(cap_app), err, reqmsg, response);
        }
        );
    }
    else
    {
        if (type == config_type::CT_ADD_SECONDARY)
            kill_app(std::move(app));
    }
}
Example #12
0
	void on_connected(const error_code& ec)
	{
		if(ec)
		{
			std::cout<<ec.message()<<std::endl;
			return;
		}
		std::cout<<"connected ppc succeed!"<<std::endl;
		socket_->disconnected_signal().bind(&this_type::on_disconnected,this,_1);

		if(re_connect_timer_)
			re_connect_timer_->cancel();

		std::string tracker = "/p2p-live/127.0.0.1:9082/default_channel_key/default_channel_uuid.ts";
		std::string host = "127.0.0.1:9906";

		http::request req;		
		req.url(tracker);
		req.host(host);

		safe_buffer buf;
		safe_buffer_io bio(&buf);
		bio<<req;

		socket_->async_send(buf);
	}
Example #13
0
	void part_file::move_partfile(std::string const& path, error_code& ec)
	{
		std::lock_guard<std::mutex> l(m_mutex);

		flush_metadata_impl(ec);
		if (ec) return;

		m_file.close();

		if (!m_piece_map.empty())
		{
			std::string old_path = combine_path(m_path, m_name);
			std::string new_path = combine_path(path, m_name);

			rename(old_path, new_path, ec);
			if (ec == boost::system::errc::no_such_file_or_directory)
				ec.clear();

			if (ec)
			{
				copy_file(old_path, new_path, ec);
				if (ec) return;
				remove(old_path, ec);
			}
		}
		m_path = path;
	}
Example #14
0
void callback(int mapping, address const& ip, int port, int protocol, error_code const& err)
{
	callback_info info = {mapping, port, err};
	callbacks.push_back(info);
	std::cerr << "mapping: " << mapping << ", port: " << port << ", IP: " << ip
		<< ", proto: " << protocol << ", error: \"" << err.message() << "\"\n";
}
Example #15
0
boost::uint64_t TsDemuxer::get_end_time(
    error_code & ec)
{
    if (!is_open(ec)) {
        return 0;
    }
    boost::uint64_t beg = archive_.tellg();
    archive_.seekg(0, std::ios::end);
    assert(archive_);
    boost::uint64_t end = archive_.tellg();
    assert(end > TsPacket::PACKET_SIZE);
    end = (end / TsPacket::PACKET_SIZE) * TsPacket::PACKET_SIZE;
    if (parse_offset2_ + TsPacket::PACKET_SIZE * 20 < end) {
        parse_offset2_ = end - TsPacket::PACKET_SIZE * 20;
    }
    if (parse_offset2_ <= parse_offset_) {
        archive_.seekg(beg, std::ios::beg);
        return get_cur_time(ec);
    } else {
        archive_.seekg(parse_offset2_, std::ios::beg);
        assert(archive_);
        while (parse_offset2_ <= end && get_packet(pkt2_, ec)) {
            parse_offset2_ += TsPacket::PACKET_SIZE;
            archive_.seekg(parse_offset2_, std::ios::beg);
        }
        ec.clear();
        archive_.seekg(beg, std::ios::beg);
        boost::uint64_t pcr = time_pcr2_.transfer(
                                  ((boost::uint64_t)pkt2_.adaptation.program_clock_reference_base) << 1);
        pcr /= (TsPacket::TIME_SCALE / 1000);
        return pcr > timestamp_offset_ms_ ? pcr  - timestamp_offset_ms_ : 0;
    }
}
Example #16
0
static void reportError(StringRef Input, error_code EC) {
  if (Input == "-")
    Input = "<stdin>";

  errs() << Input << ": " << EC.message() << "\n";
  errs().flush();
}
Example #17
0
static bool error(error_code EC, Twine Path = Twine()) {
  if (EC) {
    error(EC.message(), Path);
    return true;
  }
  return false;
}
	void udp_tracker_connection::fail(error_code const& ec, int code
		, char const* msg, int interval, int min_interval)
	{
		// m_target failed. remove it from the endpoint list
		std::list<tcp::endpoint>::iterator i = std::find(m_endpoints.begin()
			, m_endpoints.end(), tcp::endpoint(m_target.address(), m_target.port()));

		if (i != m_endpoints.end()) m_endpoints.erase(i);

		// if that was the last one, fail the whole announce
		if (m_endpoints.empty())
		{
			tracker_connection::fail(ec, code, msg, interval, min_interval);
			return;
		}

#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
		boost::shared_ptr<request_callback> cb = requester();
		if (cb) cb->debug_log("*** UDP_TRACKER [ host: \"%s\" ip: \"%s\" | error: \"%s\" ]"
			, m_hostname.c_str(), print_endpoint(m_target).c_str(), ec.message().c_str());
#endif

		// pick another target endpoint and try again
		m_target = pick_target_endpoint();

#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING
		if (cb) cb->debug_log("*** UDP_TRACKER trying next IP [ host: \"%s\" ip: \"%s\" ]"
			, m_hostname.c_str(), print_endpoint(m_target).c_str());
#endif
		m_ses.m_io_service.post(boost::bind(
			&udp_tracker_connection::start_announce, self()));
	}
Example #19
0
void MAVConnUDP::async_sendto_end(error_code error, size_t bytes_transferred)
{
	if (error) {
		logError(PFXd "sendto: %s", channel, error.message().c_str());
		close();
		return;
	}

	iostat_tx_add(bytes_transferred);
	lock_guard lock(mutex);
	if (tx_q.empty()) {
		tx_in_progress = false;
		return;
	}

	MsgBuffer *buf = tx_q.front();
	buf->pos += bytes_transferred;
	if (buf->nbytes() == 0) {
		tx_q.pop_front();
		delete buf;
	}

	if (!tx_q.empty())
		do_sendto(false);
	else
		tx_in_progress = false;
}
Example #20
0
void MAVConnUDP::async_receive_end(error_code error, size_t bytes_transferred)
{
	mavlink_message_t message;
	mavlink_status_t status;

	if (error) {
		logError(PFXd "receive: %s", channel, error.message().c_str());
		close();
		return;
	}

	if (remote_ep != last_remote_ep) {
		logInform(PFXd "Remote address: %s", channel, to_string_ss(remote_ep).c_str());
		remote_exists = true;
		last_remote_ep = remote_ep;
	}

	iostat_rx_add(bytes_transferred);
	for (size_t i = 0; i < bytes_transferred; i++) {
		if (mavlink_parse_char(channel, rx_buf[i], &message, &status)) {
			logDebug(PFXd "recv: Message-Id: %d [%d bytes] Sys-Id: %d Comp-Id: %d Seq: %d",
					channel, message.msgid, message.len, message.sysid, message.compid, message.seq);

			/* emit */ message_received(&message, message.sysid, message.compid);
		}
	}

	do_recvfrom();
}
Example #21
0
void peer_conn::close(char const* fmt, error_code const& ec)
{
	end_time = clock_type::now();
	char tmp[1024];

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
	std::snprintf(tmp, sizeof(tmp), fmt, ec.message().c_str());
#ifdef __clang__
#pragma clang diagnostic pop
#endif
	int time = int(total_milliseconds(end_time - start_time));
	if (time == 0) time = 1;
	double const up = (std::int64_t(blocks_sent) * 0x4000) / time / 1000.0;
	double const down = (std::int64_t(blocks_received) * 0x4000) / time / 1000.0;
	error_code e;

	char ep_str[200];
	address const& addr = s.local_endpoint(e).address();
#if TORRENT_USE_IPV6
	if (addr.is_v6())
		std::snprintf(ep_str, sizeof(ep_str), "[%s]:%d", addr.to_string(e).c_str()
			, s.local_endpoint(e).port());
	else
#endif
		std::snprintf(ep_str, sizeof(ep_str), "%s:%d", addr.to_string(e).c_str()
			, s.local_endpoint(e).port());
	std::printf("%s ep: %s sent: %d received: %d duration: %d ms up: %.1fMB/s down: %.1fMB/s\n"
		, tmp, ep_str, blocks_sent, blocks_received, time, up, down);
}
Example #22
0
	directory::directory(std::string const& path, error_code& ec)
		: m_done(false)
	{
		ec.clear();
#ifdef TORRENT_WINDOWS
		// the path passed to FindFirstFile() must be
		// a pattern
		std::string f = convert_separators(path);
		if (!f.empty() && f[f.size()-1] != '\\') f += "\\*";
		else f += "*";
#if TORRENT_USE_WSTRING
#define FindFirstFile_ FindFirstFileW
		std::wstring p = convert_to_wstring(f);
#else
#define FindFirstFile_ FindFirstFileA
		std::string p = convert_to_native(f);
#endif
		m_handle = FindFirstFile_(p.c_str(), &m_fd);
		if (m_handle == INVALID_HANDLE_VALUE)
		{
			ec.assign(GetLastError(), boost::system::get_system_category());
			m_done = true;
			return;
		}
#else

		memset(&m_dirent, 0, sizeof(dirent));
		m_name[0] = 0;

		// the path passed to opendir() may not
		// end with a /
		std::string p = path;
		if (!path.empty() && path[path.size()-1] == '/')
			p.resize(path.size()-1);

		p = convert_to_native(p);
		m_handle = opendir(p.c_str());
		if (m_handle == 0)
		{
			ec.assign(errno, boost::system::get_generic_category());
			m_done = true;
			return;
		}
		// read the first entry
		next(ec);
#endif
	}
Example #23
0
	url_seed_alert::url_seed_alert(
		torrent_handle const& h
		, std::string const& u
		, error_code const& e)
		: torrent_alert(h)
		, url(u)
		, msg(convert_from_native(e.message()))
	{}
Example #24
0
bool  websocket::check_err(error_code const& err, string const& reason)
{
	if ( err )
	{
		return check_err(false, reason + ": " + err.message());
	}
	return true;
}
inline void clear_error(error_code& ec)
{
#if defined(ASIOEXT_USE_BOOST_ASIO) || defined(ASIO_HAS_STD_SYSTEM_ERROR)
  ec.clear();
#else
  ec = error_code();
#endif
}
    void on_error(error_code const& code)
    {
        if (code)
        {
            if  // usually, by on_receive
               ((code.category() == error::misc_category    && code.value   () == error::eof)               ||

                // and these - by on_send
                (code.category() == error::system_category  && code.value   () == error::connection_reset)  ||
                (code.category() == error::system_category  && code.value   () == error::broken_pipe     ))
            {
                on_discon_(code);
            }
            else
                on_error_(code);
        }
    }
Example #27
0
void callback(int mapping, address extip, int port, error_code const& err)
{
    std::cerr
            << "mapping: " << mapping
            << ", port: " << port
            << ", external-IP: " << print_address(extip)
            << ", error: \"" << err.message() << "\"\n";
}
Example #28
0
static bool error(error_code ec) {
  if (!ec) return false;

  outs() << "Cpu0RelocationHandler.cpp : error reading file: " 
         << ec.message() << ".\n";
  outs().flush();
  return true;
}
Example #29
0
void callback(int mapping, address const& ip, int port, error_code const& err)
{
	callback_info info = {mapping, port, err};
	callbacks.push_back(info);
	std::cerr << "mapping: " << mapping << ", port: " << port << ", IP: " << ip
		<< ", error: \"" << err.message() << "\"\n";
	//TODO: store the callbacks and verify that the ports were successful
}
Example #30
0
	scrape_failed_alert::scrape_failed_alert(torrent_handle const& h
		, std::string const& u
		, error_code const& e)
		: tracker_alert(h, u)
		, msg(convert_from_native(e.message()))
	{
		TORRENT_ASSERT(!url.empty());
	}