int main() { { std::unique_ptr<B> bptr(new B); std::unique_ptr<A> aptr(new A); testAssign(aptr, bptr); } assert(A::count == 0); assert(B::count == 0); { Deleter<B> del(42); std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del)); std::unique_ptr<A, Deleter<A> > aptr(new A); testAssign(aptr, bptr); checkDeleter(aptr, bptr, 42, 0); } assert(A::count == 0); assert(B::count == 0); { CDeleter<A> adel(6); CDeleter<B> bdel(42); std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel); std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel); testAssign(aptr, bptr); checkDeleter(aptr, bptr, 42, 42); } assert(A::count == 0); assert(B::count == 0); }
void ServicePort::open(IPAddressList ips, uint16_t port) { m_serverPort = port; m_pendingStart = false; for(IPAddressList::iterator ip = ips.begin(); ip != ips.end(); ++ip){ try{ // std::cout << "\n" << ip->to_string() << "\n"; Acceptor_ptr aptr(new boost::asio::ip::tcp::acceptor(m_io_service, boost::asio::ip::tcp::endpoint(*ip, m_serverPort))); aptr->set_option(boost::asio::ip::tcp::no_delay(true)); accept(aptr); m_tcp_acceptors.push_back(aptr); } catch(boost::system::system_error& e){ if(m_logError){ LOG_MESSAGE("NETWORK", LOGTYPE_ERROR, 1, e.what()); m_logError = false; } m_pendingStart = true; g_scheduler.addEvent(createSchedulerTask(5000, boost::bind(&ServicePort::openAcceptor, boost::weak_ptr<ServicePort>(shared_from_this()), *ip, port))); } } }
static PyObject * create_graphs(PyObject *self, PyObject *args) { int n; if (!PyArg_ParseTuple(args, "i", &n)) return NULL; for(int i=0;i<n;i++) { std::shared_ptr<MTC::accessibility::Accessibility> aptr(new MTC::accessibility::Accessibility); sas.push_back(aptr); } return Py_None; }
int MapSocket::ProcessIncoming(WorldPacket* new_pct) { MANGOS_ASSERT(new_pct); // manage memory ;) ACE_Auto_Ptr<WorldPacket> aptr(new_pct); const ACE_UINT16 opcode = new_pct->GetOpcode(); if (opcode >= MAX_NODES_OPCODES) { sLog.outError("NodeSession: received nonexistent opcode 0x%.4X", opcode); return -1; } if (closing_) return -1; new_pct->FillPacketTime(WorldTimer::getMSTime()); switch (opcode) { case MMSG_HELLO: case NMSG_HELLO: { aptr.release(); if (!m_Session) // Register Master -> Node session here m_Session = new NodeSession(this); m_Session->QueuePacket(new_pct); break; } default: { ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1); if (m_Session != NULL) { // OK, give the packet to WorldSession aptr.release(); // WARNINIG here we call it with locks held. // Its possible to cause deadlock if QueuePacket calls back m_Session->QueuePacket(new_pct); return 0; } else { sLog.outError("MapSocket::ProcessIncoming: No session created (opcode:%u)", uint32(opcode)); return -1; } } } return 0; }
void TripleBandLinearOp::axpyb(const Array& a, const TripleBandLinearOp& x, const TripleBandLinearOp& y, const Array& b) { const Size size = mesher_->layout()->size(); Real *diag(diag_.get()); Real *lower(lower_.get()); Real *upper(upper_.get()); const Real *y_diag (y.diag_.get()); const Real *y_lower(y.lower_.get()); const Real *y_upper(y.upper_.get()); if (a.empty()) { if (b.empty()) { //#pragma omp parallel for for (Size i=0; i < size; ++i) { diag[i] = y_diag[i]; lower[i] = y_lower[i]; upper[i] = y_upper[i]; } } else { Array::const_iterator bptr(b.begin()); const Size binc = (b.size() > 1) ? 1 : 0; //#pragma omp parallel for for (Size i=0; i < size; ++i) { diag[i] = y_diag[i] + bptr[i*binc]; lower[i] = y_lower[i]; upper[i] = y_upper[i]; } } } else if (b.empty()) { Array::const_iterator aptr(a.begin()); const Size ainc = (a.size() > 1) ? 1 : 0; const Real *x_diag (x.diag_.get()); const Real *x_lower(x.lower_.get()); const Real *x_upper(x.upper_.get()); //#pragma omp parallel for for (Size i=0; i < size; ++i) { const Real s = aptr[i*ainc]; diag[i] = y_diag[i] + s*x_diag[i]; lower[i] = y_lower[i] + s*x_lower[i]; upper[i] = y_upper[i] + s*x_upper[i]; } } else { Array::const_iterator bptr(b.begin()); const Size binc = (b.size() > 1) ? 1 : 0; Array::const_iterator aptr(a.begin()); const Size ainc = (a.size() > 1) ? 1 : 0; const Real *x_diag (x.diag_.get()); const Real *x_lower(x.lower_.get()); const Real *x_upper(x.upper_.get()); //#pragma omp parallel for for (Size i=0; i < size; ++i) { const Real s = aptr[i*ainc]; diag[i] = y_diag[i] + s*x_diag[i] + bptr[i*binc]; lower[i] = y_lower[i] + s*x_lower[i]; upper[i] = y_upper[i] + s*x_upper[i]; } } }
int WorldSocket::ProcessIncoming(WorldPacket* new_pct) { MANGOS_ASSERT(new_pct); // manage memory ;) ACE_Auto_Ptr<WorldPacket> aptr(new_pct); const ACE_UINT16 opcode = new_pct->GetOpcode(); if (opcode >= NUM_MSG_TYPES) { sLog.outError("SESSION: received nonexistent opcode 0x%.4X", opcode); return -1; } if (closing_) { return -1; } // Dump received packet. sLog.outWorldPacketDump(uint32(get_handle()), new_pct->GetOpcode(), new_pct->GetOpcodeName(), new_pct, true); try { switch (opcode) { case CMSG_PING: return HandlePing(*new_pct); case CMSG_AUTH_SESSION: if (m_Session) { sLog.outError("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again"); return -1; } if (!sEluna->OnPacketReceive(m_Session, *new_pct)) return 0; return HandleAuthSession(*new_pct); case CMSG_KEEP_ALIVE: DEBUG_LOG("CMSG_KEEP_ALIVE ,size: " SIZEFMTD " ", new_pct->size()); sEluna->OnPacketReceive(m_Session, *new_pct); return 0; default: { ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1); if (m_Session != NULL) { // OK ,give the packet to WorldSession aptr.release(); // WARNING here we call it with locks held. // Its possible to cause deadlock if QueuePacket calls back m_Session->QueuePacket(new_pct); return 0; } else { sLog.outError("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode)); return -1; } } } } catch (ByteBufferException&) { sLog.outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i.", opcode, GetRemoteAddress().c_str(), m_Session ? m_Session->GetAccountId() : -1); if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) { DEBUG_LOG("Dumping error-causing packet:"); new_pct->hexlike(); } if (sWorld.getConfig(CONFIG_BOOL_KICK_PLAYER_ON_BAD_PACKET)) { DETAIL_LOG("Disconnecting session [account id %i / address %s] for badly formatted packet.", m_Session ? m_Session->GetAccountId() : -1, GetRemoteAddress().c_str()); return -1; } else { return 0; } } ACE_NOTREACHED(return 0); }
bool WorldSocket::ProcessPacket(WorldPacket* new_pct) { MANGOS_ASSERT(new_pct); // manage memory ;) std::auto_ptr<WorldPacket> aptr(new_pct); const uint16 opcode = new_pct->GetOpcode(); if (opcode >= NUM_MSG_TYPES) { sLog.outError("SESSION: received nonexistent opcode 0x%.4X", opcode); return false; } if (IsClosed()) return false; // Dump received packet. sLog.outWorldPacketDump(native_handle(), new_pct->GetOpcode(), new_pct->GetOpcodeName(), new_pct, true); try { switch (opcode) { case CMSG_PING: return HandlePing(*new_pct); case CMSG_AUTH_SESSION: if (session_) { sLog.outError("WorldSocket::ProcessIncoming: Player send CMSG_AUTH_SESSION again"); return false; } return HandleAuthSession(*new_pct); case CMSG_KEEP_ALIVE: DEBUG_LOG("CMSG_KEEP_ALIVE ,size: " SIZEFMTD " ", new_pct->size()); return true; default: { GuardType Guard(session_lock_); if (session_ != NULL) { // OK ,give the packet to WorldSession aptr.release(); // WARNING here we call it with locks held. // Its possible to cause deadlock if QueuePacket calls back session_->QueuePacket(new_pct); return true; } else { sLog.outError("WorldSocket::ProcessIncoming: Client not authed opcode = %u", uint32(opcode)); return false; } } } } catch (ByteBufferException&) { sLog.outError("WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet (opcode: %u) from client %s, accountid=%i.", opcode, GetRemoteAddress().c_str(), session_ ? session_->GetAccountId() : -1); if (sLog.HasLogLevelOrHigher(LOG_LVL_DEBUG)) { DEBUG_LOG("Dumping error-causing packet:"); new_pct->hexlike(); } if (sWorld.getConfig(CONFIG_BOOL_KICK_PLAYER_ON_BAD_PACKET)) { DETAIL_LOG("Disconnecting session [account id %i / address %s] for badly formatted packet.", session_ ? session_->GetAccountId() : -1, GetRemoteAddress().c_str()); return false; } } packet_ = nullptr; return true; }