//we ensure in that function that connect to all events are already setup when we said we are connect. //that way we can't be connected without being fully ready. qi::FutureSync<void> ServiceDirectoryClient::connect(const qi::Url &serviceDirectoryURL) { if (isConnected()) { const char* s = "Session is already connected"; qiLogInfo() << s; return qi::makeFutureError<void>(s); } _sdSocket = qi::makeTransportSocket(serviceDirectoryURL.protocol()); if (!_sdSocket) return qi::makeFutureError<void>(std::string("unrecognized protocol '") + serviceDirectoryURL.protocol() + "' in url '" + serviceDirectoryURL.str() + "'"); _sdSocketDisconnectedSignalLink = _sdSocket->disconnected.connect(&ServiceDirectoryClient::onSocketDisconnected, this, _1); _remoteObject.setTransportSocket(_sdSocket); qi::Promise<void> promise; qi::Future<void> fut = _sdSocket->connect(serviceDirectoryURL); fut.connect(&ServiceDirectoryClient::onSocketConnected, this, _1, promise); return promise.future(); }
qi::Future<void> TransportServer::listen(const qi::Url &url, qi::EventLoop* ctx) { TransportServerImplPtr impl; if (url.protocol() == "tcp" || url.protocol() == "tcps") { impl = TransportServerAsioPrivate::make(this, ctx); } else { const char* s = "Unrecognized protocol to create the TransportServer."; qiLogError() << s; return qi::makeFutureError<void>(s); } { boost::mutex::scoped_lock l(_implMutex); _impl.push_back(impl); } return impl->listen(url); }