void ActorSet::reapZombieActors() { // delete zombie actors ActorMap::iterator iter = actors.begin(); ActorMap::iterator nextIter; while(iter != actors.end()) { // Get an iterator to the next element (or the end of the map) nextIter = iter; nextIter++; pair<OBJECT_ID, ActorPtr> p = *iter; OBJECT_ID id = p.first; ActorPtr actor = p.second; if(actor && actor->zombie) { removeSubscriber(id); actors.erase(id); getActorFactory().remove(id); } iter = nextIter; } }
void WebEventServiceImpl::sendImpl(Poco::SharedPtr<Poco::Net::WebSocket> pWS, const std::string& message) { try { pWS->sendFrame(message.data(), message.size()); } catch (Poco::Exception& exc) { _pContext->logger().error("Error while sending frame: " + exc.displayText()); removeSubscriber(pWS, false); } }
bool ByteArray::addSubscriber(GlobalMemorySubscriber* subscriber) { if(m_length >= Domain::GLOBAL_MEMORY_MIN_SIZE) { removeSubscriber(subscriber); SubscriberLink *newLink = new (MMgc::GC::GetGC(subscriber)) SubscriberLink; newLink->weakSubscriber = subscriber->GetWeakRef(); MMgc::GC::WriteBarrier(&newLink->next, m_subscriberRoot); MMgc::GC::WriteBarrier(&m_subscriberRoot, newLink); // notify the new "subscriber" of the current state of the world subscriber->notifyGlobalMemoryChanged(m_array, m_length); return true; } return false; }
void ActorSet::destroy() { // delete all actors while(!actors.empty()) { ActorMap::iterator iter = actors.begin(); pair<OBJECT_ID, ActorPtr> p = *iter; OBJECT_ID id = p.first; ActorPtr actor = p.second; removeSubscriber(id); getActorFactory().remove(id); actors.erase(iter); } displayDebugRendering = false; }
void WebEventServiceImpl::receiveImpl(Poco::SharedPtr<Poco::Net::WebSocket> pWS) { try { Poco::Buffer<char> buffer(4096); int flags; int n = pWS->receiveFrame(buffer.begin(), buffer.size(), flags); _pContext->logger().debug(Poco::format("Frame received (length=%d, flags=0x%x).", n, unsigned(flags))); if (flags & Poco::Net::WebSocket::FRAME_OP_PONG) { _pContext->logger().debug("Received unsolicited PONG frame - ignoring."); _mainQueue.enqueueNotification(new WatchSocketNotification(*this, *pWS)); return; } if ((flags & Poco::Net::WebSocket::FRAME_OP_CLOSE) || n == 0) { removeSubscriber(pWS, true); return; } const char* it = buffer.begin(); const char* end = buffer.begin() + n; std::string verb; while (it != end && *it != ' ') verb += *it++; if (verb == SUBSCRIBE || verb == UNSUBSCRIBE || verb == NOTIFY) { while (it != end && *it == ' ') ++it; std::set<std::string> subjectNames; while (it != end && *it != ' ') { std::string subject; while (it != end && *it != ',' && *it != ' ') subject += *it++; if (it != end) { subjectNames.insert(subject); if (*it == ',') it++; // skip ',' } } while (it != end && *it == ' ') ++it; std::string version; while (it != end && *it != '\r' && *it != '\n') version += *it++; if (it != end && *it == '\r') ++it; if (it != end && *it == '\n') ++it; if (version == VERSION) { if (verb == SUBSCRIBE) { subscribe(pWS, subjectNames); } else if (verb == UNSUBSCRIBE) { unsubscribe(pWS, subjectNames); } else if (verb == NOTIFY) { std::string data; while (it != end) data += *it++; for (std::set<std::string>::const_iterator it = subjectNames.begin(); it != subjectNames.end(); ++it) { if (*it == SYSTEM_PING) { std::string pong(NOTIFY); pong += ' '; pong += SYSTEM_PONG; pong += ' '; pong += VERSION; pong += "\r\n"; pong += data; send(pWS, pong); } else { notify(*it, data); } } } _mainQueue.enqueueNotification(new WatchSocketNotification(*this, *pWS)); return; } } _pContext->logger().notice("Client protocol violation. Closing WebSocket."); } catch (Poco::Exception& exc) { _pContext->logger().error("Error while receiving frame: " + exc.displayText()); } removeSubscriber(pWS, false); }