本文整理汇总了C++中boost::weak_ptr类的典型用法代码示例。如果您正苦于以下问题:C++ weak_ptr类的具体用法?C++ weak_ptr怎么用?C++ weak_ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了weak_ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleWriteTimeout
void Connection::handleWriteTimeout(boost::weak_ptr<Connection> weak, const boost::system::error_code& error)
{
if(error == boost::asio::error::operation_aborted || weak.expired())
return;
if(shared_ptr<Connection> connection = weak.lock())
{
#ifdef __DEBUG_NET_DETAIL__
std::clog << "Connection::handleWriteTimeout" << std::endl;
#endif
connection->onWriteTimeout();
}
}
示例2: handleWriteTimeout
void Connection::handleWriteTimeout(boost::weak_ptr<Connection> weak_conn, const boost::system::error_code& error)
{
if (error == boost::asio::error::operation_aborted) {
return;
}
if (weak_conn.expired()) {
return;
}
if (Connection_ptr connection = weak_conn.lock()) {
connection->onWriteTimeout();
}
}
示例3: openAcceptor
void ServicePort::openAcceptor(boost::weak_ptr<ServicePort> weak_service, IPAddress ip, uint16_t port)
{
if(weak_service.expired()){
return;
}
if(ServicePort_ptr service = weak_service.lock()){
#ifdef __DEBUG_NET_DETAIL__
std::cout << "ServicePort::openAcceptor" << std::endl;
#endif
IPAddressList ips;
ips.push_back(ip);
service->open(ips, port);
}
}
示例4: handleReadTimeout
void Connection::handleReadTimeout(boost::weak_ptr<Connection> weak_conn, const boost::system::error_code& error)
{
if(error != boost::asio::error::operation_aborted){
if(weak_conn.expired()){
return;
}
if(shared_ptr<Connection> connection = weak_conn.lock()){
#ifdef __DEBUG_NET_DETAIL__
std::cout << "Connection::handleReadTimeout" << std::endl;
#endif
connection->onReadTimeout();
}
}
}
示例5: onServiceInfoResultIfExists
inline void onServiceInfoResultIfExists(Session_Service* s, qi::Future<qi::ServiceInfo> f,
long requestId, std::string protocol, boost::weak_ptr<Session_Service> self)
{
boost::shared_ptr<Session_Service> sself = self.lock();
if (sself)
sself->onServiceInfoResult(f, requestId, protocol);
}
示例6: add
void add(boost::weak_ptr<SpotLightCalculator> light)
{
for(unsigned int i = 0; i < spots.size(); ++i)
assert(spots[i].lock() != light.lock());
spots.push_back(light);
}
示例7: TimerEntry
void PeerSet::TimerEntry (boost::weak_ptr<PeerSet> wptr, const boost::system::error_code& result)
{
if (result == boost::asio::error::operation_aborted)
return;
boost::shared_ptr<PeerSet> ptr = wptr.lock ();
if (ptr)
{
if (ptr->mTxnData)
{
getApp().getJobQueue ().addJob (jtTXN_DATA, "timerEntryTxn",
BIND_TYPE (&PeerSet::TimerJobEntry, P_1, ptr));
}
else
{
int jc = getApp().getJobQueue ().getJobCountTotal (jtLEDGER_DATA);
if (jc > 4)
{
WriteLog (lsDEBUG, InboundLedger) << "Deferring PeerSet timer due to load";
ptr->setTimer ();
}
else
getApp().getJobQueue ().addJob (jtLEDGER_DATA, "timerEntryLgr",
BIND_TYPE (&PeerSet::TimerJobEntry, P_1, ptr));
}
}
}
示例8: operator
bool operator()(boost::weak_ptr<T> arg) const {
boost::shared_ptr<T> sp=arg.lock();
if (!sp) {
return false;
}
return func_(*sp,t_);
}
示例9:
http_seed_connection::http_seed_connection(
session_impl& ses
, boost::weak_ptr<torrent> t
, boost::shared_ptr<socket_type> s
, tcp::endpoint const& remote
, std::string const& url
, policy::peer* peerinfo
, std::string const& auth
, web_seed_entry::headers_t const& extra_headers)
: web_connection_base(ses, t, s, remote, url, peerinfo, auth, extra_headers)
, m_url(url)
, m_response_left(0)
, m_chunk_pos(0)
, m_partial_chunk_header(0)
{
INVARIANT_CHECK;
if (!ses.settings().report_web_seed_downloads)
ignore_stats(true);
shared_ptr<torrent> tor = t.lock();
TORRENT_ASSERT(tor);
int blocks_per_piece = tor->torrent_file().piece_length() / tor->block_size();
// multiply with the blocks per piece since that many requests are
// merged into one http request
m_max_out_request_queue = ses.settings().urlseed_pipeline_size
* blocks_per_piece;
prefer_whole_pieces(1);
#ifdef TORRENT_VERBOSE_LOGGING
peer_log("*** http_seed_connection");
#endif
}
示例10: save
inline void save(
Archive & ar,
const boost::weak_ptr< T > &t,
const unsigned int /* file_version */
){
const boost::shared_ptr< T > sp = t.lock();
ar << boost::serialization::make_nvp("weak_ptr", sp);
}
示例11: weak_call
int weak_call(int (X::*ptmf)() const, boost::weak_ptr<X> const& wp)
{
auto locked = wp.lock();
if (!locked)
throw boost::bad_weak_ptr();
return ((*locked).*ptmf)();
}
示例12: queue_request
void tracker_manager::queue_request(
io_service& ios
, connection_queue& cc
, tracker_request req
, std::string const& auth
, boost::weak_ptr<request_callback> c)
{
mutex_t::scoped_lock l(m_mutex);
TORRENT_ASSERT(req.num_want >= 0);
TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
if (m_abort && req.event != tracker_request::stopped) return;
if (req.event == tracker_request::stopped)
req.num_want = 0;
TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped);
if (m_abort && req.event != tracker_request::stopped)
return;
std::string protocol = req.url.substr(0, req.url.find(':'));
boost::intrusive_ptr<tracker_connection> con;
#ifdef TORRENT_USE_OPENSSL
if (protocol == "http" || protocol == "https")
#else
if (protocol == "http")
#endif
{
con = new http_tracker_connection(
ios, cc, *this, req, c
, m_ses, m_proxy, auth
#if TORRENT_USE_I2P
, &m_ses.m_i2p_conn
#endif
);
}
else if (protocol == "udp")
{
con = new udp_tracker_connection(
ios, cc, *this, req , c, m_ses
, m_proxy);
}
else
{
// we need to post the error to avoid deadlock
if (boost::shared_ptr<request_callback> r = c.lock())
ios.post(boost::bind(&request_callback::tracker_request_error, r, req
, -1, error_code(errors::unsupported_url_protocol)
, "", 0));
return;
}
m_connections.push_back(con);
boost::shared_ptr<request_callback> cb = con->requester();
if (cb) cb->m_manager = this;
con->start();
}
示例13: blockArrived
ProcessResult GetDisco::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){
ServiceDiscovery::ref sd=vf.lock();
if (!sd) return CANCEL;
if (block->getAttribute("id")==idinfo) {
if (block->getAttribute("type")=="result") {
sd->infoReply=block->findChildNamespace("query", "http://jabber.org/protocol/disco#info");
} else {
if (block->getAttribute("type")=="error") {
sd->infoReply=block->getChildByName("error");
}
}
SendMessage(sd->getHWnd(), WM_NOTIFY_BLOCKARRIVED, 0,0);
return BLOCK_PROCESSED;
}
if (block->getAttribute("id")==iditems) {
if (block->getAttribute("type")=="result") {
sd->itemReply=block->findChildNamespace("query", "http://jabber.org/protocol/disco#items");
} else {
if (block->getAttribute("type")=="error") {
sd->itemReply=block->getChildByName("error");
}
}
SendMessage(sd->getHWnd(), WM_NOTIFY_BLOCKARRIVED, 0,0);
return LAST_BLOCK_PROCESSED;
}
return BLOCK_REJECTED;
}
示例14: eventOk
void DiscoListView::eventOk() {
ServiceDiscovery::ref sd=serviceDiscovery.lock();
if (!sd) return;
DiscoItem::ref c=boost::dynamic_pointer_cast<DiscoItem> (cursorPos);
if (c) {
sd->discoverJid(c->jid, c->node);
sd->go();
return;
}
DiscoCommand::ref dc=boost::dynamic_pointer_cast<DiscoCommand> (cursorPos);
if (dc) {
switch (dc->cmdId) {
case DiscoCommand::BACK:
sd->back();
return;
case DiscoCommand::VCARD:
sd->vcard();
return;
case DiscoCommand::JOINGC:
sd->joingc();
return;
case DiscoCommand::EXECUTE:
sd->execute();
return;
case DiscoCommand::REGISTER:
sd->registerForm();
}
}
VirtualListView::eventOk();
}
示例15: runInThread
void runInThread()
{
pid_t tid = gettid();
boost::shared_ptr<pid_t> ptid = wkTid_.lock();
if (ptid)
{
*ptid = tid;
ptid.reset();
}
Rabbit::CurrentThread::t_threadName = name_.empty() ? "RabbitThread" : name_.c_str();
try
{
func_();
Rabbit::CurrentThread::t_threadName = "finished";
}
catch (...)
{
Rabbit::CurrentThread::t_threadName = "crashed";
fprintf(stderr, "some exception caught in Thread %s\n", name_.c_str());
perror("");
abort();
}
}