• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ error_code类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中error_code的典型用法代码示例。如果您正苦于以下问题:C++ error_code类的具体用法?C++ error_code怎么用?C++ error_code使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了error_code类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: _Family

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();
}
开发者ID:cristianadam,项目名称:io2d,代码行数:30,代码来源:font_resource_factory.cpp


示例2: on_piece_write

	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;
		}
	}
开发者ID:guangzhuwu,项目名称:p2streaming,代码行数:25,代码来源:asfile_test.cpp


示例3: bytesToRead

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;
}
开发者ID:CubeSpawn-Research,项目名称:MTConnectToolbox,代码行数:31,代码来源:XmlSocketClient.cpp


示例4: error

static bool error(error_code ec, Twine path = Twine()) {
  if (ec) {
    error(ec.message(), path);
    return true;
  }
  return false;
}
开发者ID:ebraheemk,项目名称:llvm-picoblaze,代码行数:7,代码来源:llvm-nm.cpp


示例5: resolve

 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();
     }
 }
开发者ID:huangyt,项目名称:MyProjects,代码行数:25,代码来源:ResolverService.cpp


示例6: close

	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;
	}
开发者ID:Athorcis,项目名称:libtorrent,代码行数:25,代码来源:connection_tester.cpp


示例7: save

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);
}
开发者ID:arvidn,项目名称:libtorrent-webui,代码行数:33,代码来源:save_settings.cpp


示例8: complete_io

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);
            }
        }
    }
}
开发者ID:shengofsun,项目名称:rDSN,代码行数:35,代码来源:disk_engine.cpp


示例9: run_test

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);
}
开发者ID:SiderZhang,项目名称:p2pns3,代码行数:30,代码来源:test_http_connection.cpp


示例10: if

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));
    }
}
开发者ID:glglwty,项目名称:rDSN,代码行数:35,代码来源:daemon.server.cpp


示例11: on_connected

	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);
	}
开发者ID:guangzhuwu,项目名称:p2streaming,代码行数:26,代码来源:test_player.cpp


示例12: move_partfile

	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;
	}
开发者ID:kmachin3,项目名称:libtorrent,代码行数:27,代码来源:part_file.cpp


示例13: callback

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";
}
开发者ID:Jackarain,项目名称:libtorrent,代码行数:7,代码来源:test_upnp.cpp


示例14: get_cur_time

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;
    }
}
开发者ID:uvbs,项目名称:MyProjects,代码行数:33,代码来源:TsDemuxer.cpp


示例15: error

static bool error(error_code EC, Twine Path = Twine()) {
  if (EC) {
    error(EC.message(), Path);
    return true;
  }
  return false;
}
开发者ID:ADonut,项目名称:LLVM-GPGPU,代码行数:7,代码来源:llvm-nm.cpp


示例16: fail

	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()));
	}
开发者ID:mrmichalis,项目名称:libtorrent-code,代码行数:32,代码来源:udp_tracker_connection.cpp


示例17: async_sendto_end

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;
}
开发者ID:15gr830,项目名称:mavros,代码行数:27,代码来源:udp.cpp


示例18: async_receive_end

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();
}
开发者ID:15gr830,项目名称:mavros,代码行数:29,代码来源:udp.cpp


示例19: sizeof

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);
}
开发者ID:poltina,项目名称:libtorrent,代码行数:32,代码来源:bittorrent_peer.cpp


示例20: sizeof

	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
	}
开发者ID:bird1015,项目名称:avplayer,代码行数:47,代码来源:file.cpp



注:本文中的error_code类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ event类代码示例发布时间:2022-05-31
下一篇:
C++ errlHndl_t类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap