void _read(const Pipe::Reader& reader, const Future<Result<Event>>& event) { CHECK(!event.isDiscarded()); // Ignore enqueued events from the previous Subscribe call reader. if (subscribed.isNone() || subscribed->reader != reader) { VLOG(1) << "Ignoring event from old stale connection"; return; } CHECK_EQ(SUBSCRIBED, state); CHECK_SOME(connectionId); // This could happen if the agent process died while sending a response. if (event.isFailed()) { LOG(ERROR) << "Failed to decode the stream of events: " << event.failure(); disconnected(connectionId.get(), event.failure()); return; } // This could happen if the agent failed over after sending an event. if (event->isNone()) { const string error = "End-Of-File received from agent. The agent closed " "the event stream"; LOG(ERROR) << error; disconnected(connectionId.get(), error); return; } if (event->isError()) { error("Failed to de-serialize event: " + event->error()); return; } receive(event.get().get(), false); read(); }
void SessionPrivate::addSdSocketToCache(Future<void> f, const qi::Url& url, qi::Promise<void> p) { qiLogDebug() << "addSocketToCache processing"; if (f.hasError()) { qiLogDebug() << "addSdSocketToCache: connect reported failure"; _serviceHandler.removeService("ServiceDirectory"); p.setError(f.error()); return; } // Allow the SD process to use the existing socket to talk to our services _serverObject.registerSocket(_sdClient.socket()); /* Allow reusing the SD socket for communicating with services. * To do this, we must add it to our socket cache, and for this we need * to know the sd machineId */ std::string mid; try { mid = _sdClient.machineId(); } catch (const std::exception& e) { // Provide a nice message for backward compatibility qiLogVerbose() << e.what(); qiLogWarning() << "Failed to obtain machineId, connection to service directory will not be reused for other services."; p.setValue(0); return; } TransportSocketPtr s = _sdClient.socket(); qiLogVerbose() << "Inserting sd to cache for " << mid <<" " << url.str() << std::endl; _socketsCache.insert(mid, s->remoteEndpoint(), s); p.setValue(0); }