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(); } }
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(); } }
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); } }
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(); } } }
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; }
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(); }
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); }
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(); } }
void runInThread() { pid_t tid = pai::concurrency::CurrentThread::tid(); boost::shared_ptr<pid_t> ptid = wkTid_.lock(); if (ptid) { *ptid = tid; ptid.reset(); } pai::concurrency::CurrentThread::t_threadName = name_.empty() ? "paiThread" : name_.c_str(); ::prctl(PR_SET_NAME, pai::concurrency::CurrentThread::t_threadName); try { func_(); pai::concurrency::CurrentThread::t_threadName = "finished"; } catch (const std::exception& ex) { pai::concurrency::CurrentThread::t_threadName = "crashed"; fprintf(stderr, "exception caught in Thread %s\n", name_.c_str()); fprintf(stderr, "reason: %s\n", ex.what()); abort(); } catch (...) { pai::concurrency::CurrentThread::t_threadName = "crashed"; fprintf(stderr, "unknown exception caught in Thread %s\n", name_.c_str()); throw; // rethrow } }
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); }
void runInThread() { DWORD tid = GetCurrentThreadId(); boost::shared_ptr<DWORD> ptid = wkTid_.lock(); if (ptid) { //set thread Id *ptid = tid; ptid.reset(); } if (name_.empty()) name_ = "zyThread"; try { func_(); name_ += "finished"; } catch (const std::exception & ex) { fprintf(stderr, "exception caught in Thread %s\n", name_.c_str()); fprintf(stderr, "reason: %s\n", ex.what()); name_ += "crashed"; abort(); } catch (...) { fprintf(stderr, "unknown exception caught in Thread %s \n", name_.c_str()); name_ += "crashed"; throw; } }
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)); } } }
bool operator()(boost::weak_ptr<T> arg) const { boost::shared_ptr<T> sp=arg.lock(); if (!sp) { return false; } return func_(*sp,t_); }
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 }
void http_connection::on_timeout(boost::weak_ptr<http_connection> p , error_code const& e) { boost::shared_ptr<http_connection> c = p.lock(); if (!c) return; if (e == asio::error::operation_aborted) return; if (c->m_last_receive + c->m_timeout < time_now()) { if (c->m_connection_ticket > -1 && !c->m_endpoints.empty()) { c->m_sock.close(); error_code ec; c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec); c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1)); } else { c->callback(asio::error::timed_out); c->close(); } return; } if (!c->m_sock.is_open()) return; error_code ec; c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec); c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1)); }
int main() { BOOST_TEST( p1.get() != 0 ); BOOST_TEST_EQ( p1.use_count(), 1 ); BOOST_TEST_EQ( p2.use_count(), 1 ); BOOST_TEST_EQ( p2.lock(), p1 ); #if !defined( BOOST_NO_CXX11_NULLPTR ) BOOST_TEST( p3.get() != 0 ); BOOST_TEST_EQ( p3.use_count(), 1 ); #endif return boost::report_errors(); }
ProcessResult GetVcard::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){ VcardForm::ref vfRef=vf.lock(); if (!vfRef) return CANCEL; vfRef->vcardArrivedNotify(block); return LAST_BLOCK_PROCESSED; }
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); }
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)(); }
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(); }
ProcessResult GetMucConfig::blockArrived(JabberDataBlockRef block, const ResourceContextRef rc){ MucConfigForm::ref ahfRef=ahf.lock(); if (!ahfRef) return CANCEL; //StringRef s=block->toXML(); ahfRef->MucConfigResultNotify(block); return LAST_BLOCK_PROCESSED; }
void SceneDict::Insert(boost::weak_ptr<zeitgeist::Leaf> leaf, const FileRef& ref) { if (leaf.expired()) { return; } mDictionary[leaf] = ref; }
static void weakDeleteCallback(const boost::weak_ptr<StockFactory>& wkFactory, Stock* stock) { shared_ptr<StockFactory> factory(wkFactory.lock()); if (factory) { factory->removeStock(stock); } delete stock; }
bool CompositePeaksPresenter::hasPeakAddModeFor(boost::weak_ptr<const Mantid::API::IPeaksWorkspace> target){ bool hasMode = false; if(auto temp = target.lock()) { auto it = this->getPresenterIteratorFromWorkspace(temp); if(it != m_subjects.end()) { hasMode = (*it)->hasPeakAddMode(); } } return hasMode; }
void ribi::trim::Face::AddBelongsTo(boost::weak_ptr<const Cell> cell) { assert(cell.lock()); m_belongs_to.push_back(cell); assert(m_belongs_to.size() <= 2); assert( (m_belongs_to.size() == 1) || (m_belongs_to.size() == 2 && m_belongs_to[0].lock() != m_belongs_to[1].lock()) ); }
void Tunnel::onHighWaterMarkWeak(const boost::weak_ptr<Tunnel>& wkTunnel, const ConnectionPtr& conn, size_t bytesToSent) { LOG_ERROR("onHighWaterMark " << conn->name() << " bytes " << bytesToSent); boost::shared_ptr<Tunnel> tunnel = wkTunnel.lock(); if (tunnel) { tunnel->onHighWaterMark(conn, bytesToSent); } }
libusb::session::sptr libusb::session::get_global_session(void){ static boost::weak_ptr<session> global_session; //not expired -> get existing session if (not global_session.expired()) return global_session.lock(); //create a new global session sptr new_global_session(new libusb_session_impl()); global_session = new_global_session; //set logging if envvar is set const char *level_string = getenv("LIBUSB_DEBUG_LEVEL"); if (level_string != NULL) { const int level = int(level_string[0] - '0'); //easy conversion to integer if (level >= 0 and level <= 3) libusb_set_debug(new_global_session->get_context(), level); } return new_global_session; }
static void stubOnTimer( boost::weak_ptr<void> weakCond, boost::function<void ()> dg) { boost::shared_ptr<void> temp = weakCond.lock(); if (temp) { dg(); } else { MORDOR_LOG_DEBUG(g_log) << " Conditionally skip in stubOnTimer!"; } }
virtual bool equal(position_interface& pos) { check_expired(); bf_position* p = dynamic_cast<bf_position*>(&pos); if (p) { p->check_expired(); return memory_.lock() == p->memory_.lock() && where_ == p->where_ ; } else { return false; } }
void check_range() const { if (range_checked_) { check_expired(); if (memory_.lock()->is_out_of_range(where_)) { if (where_ >= 0) { throw position_out_of_range_forward("Position out of range forward."); } else { throw position_out_of_range_backward("Position out of range backward."); } } } }