From cdcffbcc3c3c052afdeb772ff0167e7a90b525bb Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Wed, 19 Mar 2014 12:45:55 -0700 Subject: merging javascript branch --- cpp/src/Ice/EndpointI.cpp | 357 ++++++---------------------------------------- 1 file changed, 40 insertions(+), 317 deletions(-) (limited to 'cpp/src/Ice/EndpointI.cpp') diff --git a/cpp/src/Ice/EndpointI.cpp b/cpp/src/Ice/EndpointI.cpp index e3ce67746b9..4e160c3bcd2 100644 --- a/cpp/src/Ice/EndpointI.cpp +++ b/cpp/src/Ice/EndpointI.cpp @@ -1,6 +1,6 @@ // ********************************************************************** // -// Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved. +// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. @@ -8,357 +8,80 @@ // ********************************************************************** #include -#include -#include -#include -#include -#include using namespace std; -using namespace Ice::Instrumentation; -using namespace IceInternal; -namespace -{ - -IceUtil::Mutex* hashMutex = 0; +IceUtil::Shared* IceInternal::upCast(EndpointI* p) { return p; } +IceUtil::Shared* IceInternal::upCast(EndpointI_connectors* p) { return p; } -class Init -{ -public: - - Init() - { - hashMutex = new IceUtil::Mutex; - } - - ~Init() - { - delete hashMutex; - hashMutex = 0; - } -}; - -Init init; - -} - -Ice::LocalObject* IceInternal::upCast(EndpointI* p) { return p; } -IceUtil::Shared* IceInternal::upCast(EndpointHostResolver* p) { return p; } - -vector -IceInternal::EndpointI::connectors(const vector
& /*addrs*/, const NetworkProxyPtr& /*proxy*/) const +string +IceInternal::EndpointI::toString() const { // - // This method must be extended by endpoints which use the EndpointHostResolver to create - // connectors from IP addresses. + // WARNING: Certain features, such as proxy validation in Glacier2, + // depend on the format of proxy strings. Changes to toString() and + // methods called to generate parts of the reference string could break + // these features. Please review for all features that depend on the + // format of proxyToString() before changing this and related code. // - assert(false); - return vector(); -} - -const string& -IceInternal::EndpointI::connectionId() const -{ - return _connectionId; + return protocol() + options(); } -Ice::Int -IceInternal::EndpointI::internal_getHash() const -{ - IceUtilInternal::MutexPtrLock lock(hashMutex); - if(!_hashInitialized) - { - _hashValue = hashInit(); - } - return _hashValue; -} - -IceInternal::EndpointI::EndpointI(const std::string& connectionId) : - _connectionId(connectionId), - _hashInitialized(false) -{ -} - -IceInternal::EndpointI::EndpointI() : - _hashInitialized(false) +void +IceInternal::EndpointI::initWithOptions(vector& args) { -} + vector unknown; -#ifndef ICE_OS_WINRT - -IceInternal::EndpointHostResolver::EndpointHostResolver(const InstancePtr& instance) : - IceUtil::Thread("Ice.HostResolver"), - _instance(instance), - _protocol(instance->protocolSupport()), - _preferIPv6(instance->preferIPv6()), - _destroyed(false) -{ - __setNoDelete(true); - try + ostringstream ostr; + ostr << '`' << protocol() << " "; + for(vector::iterator p = args.begin(); p != args.end(); ++p) { - updateObserver(); - bool hasPriority = _instance->initializationData().properties->getProperty("Ice.ThreadPriority") != ""; - int priority = _instance->initializationData().properties->getPropertyAsInt("Ice.ThreadPriority"); - if(hasPriority) + if(p->find_first_of(" \t\n\r") != string::npos) { - start(0, priority); + ostr << " \"" << *p << "\""; } else { - start(); - } - } - catch(const IceUtil::Exception& ex) - { - { - Ice::Error out(_instance->initializationData().logger); - out << "cannot create thread for enpoint host resolver:\n" << ex; - } - throw; - } - __setNoDelete(false); -} - -vector -IceInternal::EndpointHostResolver::resolve(const string& host, int port, Ice::EndpointSelectionType selType, - const EndpointIPtr& endpoint) -{ - // - // Try to get the addresses without DNS lookup. If this doesn't - // work, we retry with DNS lookup (and observer). - // - NetworkProxyPtr networkProxy = _instance->networkProxy(); - if(!networkProxy) - { - vector
addrs = getAddresses(host, port, _protocol, selType, _preferIPv6, false); - if(!addrs.empty()) - { - return endpoint->connectors(addrs, 0); - } - } - - ObserverHelperT<> observer; - const CommunicatorObserverPtr& obsv = _instance->getObserver(); - if(obsv) - { - observer.attach(obsv->getEndpointLookupObserver(endpoint)); - } - - vector connectors; - try - { - if(networkProxy) - { - networkProxy = networkProxy->resolveHost(); - } - - connectors = endpoint->connectors(getAddresses(host, port, _protocol, selType, _preferIPv6, true), - networkProxy); - } - catch(const Ice::LocalException& ex) - { - observer.failed(ex.ice_name()); - throw; - } - return connectors; -} - -void -IceInternal::EndpointHostResolver::resolve(const string& host, int port, Ice::EndpointSelectionType selType, - const EndpointIPtr& endpoint, const EndpointI_connectorsPtr& callback) -{ - // - // Try to get the addresses without DNS lookup. If this doesn't work, we queue a resolve - // entry and the thread will take care of getting the endpoint addresses. - // - NetworkProxyPtr networkProxy = _instance->networkProxy(); - if(!networkProxy) - { - try - { - vector
addrs = getAddresses(host, port, _protocol, selType, _preferIPv6, false); - if(!addrs.empty()) - { - callback->connectors(endpoint->connectors(addrs, 0)); - return; - } - } - catch(const Ice::LocalException& ex) - { - callback->exception(ex); - return; + ostr << " " << *p; } } + ostr << "'"; + const string str = ostr.str(); - Lock sync(*this); - assert(!_destroyed); - - ResolveEntry entry; - entry.host = host; - entry.port = port; - entry.selType = selType; - entry.endpoint = endpoint; - entry.callback = callback; - - const CommunicatorObserverPtr& obsv = _instance->getObserver(); - if(obsv) + for(vector::size_type n = 0; n < args.size(); ++n) { - entry.observer = obsv->getEndpointLookupObserver(endpoint); - if(entry.observer) + string option = args[n]; + if(option.length() < 2 || option[0] != '-') { - entry.observer->attach(); + unknown.push_back(option); + continue; } - } - - _queue.push_back(entry); - notify(); -} - -void -IceInternal::EndpointHostResolver::destroy() -{ - Lock sync(*this); - assert(!_destroyed); - _destroyed = true; - notify(); -} -void -IceInternal::EndpointHostResolver::run() -{ - while(true) - { - ResolveEntry r; - ThreadObserverPtr threadObserver; + string argument; + if(n + 1 < args.size() && args[n + 1][0] != '-') { - Lock sync(*this); - while(!_destroyed && _queue.empty()) - { - wait(); - } - - if(_destroyed) - { - break; - } - - r = _queue.front(); - _queue.pop_front(); - threadObserver = _observer.get(); + argument = args[++n]; } - try - { - if(threadObserver) - { - threadObserver->stateChanged(ThreadStateIdle, ThreadStateInUseForOther); - } - - NetworkProxyPtr networkProxy = _instance->networkProxy(); - if(networkProxy) - { - networkProxy = networkProxy->resolveHost(); - } - - r.callback->connectors(r.endpoint->connectors(getAddresses(r.host, - r.port, - _protocol, - r.selType, - _preferIPv6, true), - networkProxy)); - - if(threadObserver) - { - threadObserver->stateChanged(ThreadStateInUseForOther, ThreadStateIdle); - } - - if(r.observer) - { - r.observer->detach(); - } - } - catch(const Ice::LocalException& ex) + if(!checkOption(option, argument, str)) { - if(r.observer) + unknown.push_back(option); + if(!argument.empty()) { - r.observer->failed(ex.ice_name()); - r.observer->detach(); + unknown.push_back(argument); } - r.callback->exception(ex); - } - } - - for(deque::const_iterator p = _queue.begin(); p != _queue.end(); ++p) - { - Ice::CommunicatorDestroyedException ex(__FILE__, __LINE__); - if(p->observer) - { - p->observer->failed(ex.ice_name()); - p->observer->detach(); } - p->callback->exception(ex); } - _queue.clear(); - if(_observer) - { - _observer.detach(); - } -} - -void -IceInternal::EndpointHostResolver::updateObserver() -{ - Lock sync(*this); - const CommunicatorObserverPtr& obsv = _instance->getObserver(); - if(obsv) - { - _observer.attach(obsv->getThreadObserver("Communicator", name(), ThreadStateIdle, _observer.get())); - } -} - -#else - -IceInternal::EndpointHostResolver::EndpointHostResolver(const InstancePtr& instance) : - _instance(instance) -{ -} - -vector -IceInternal::EndpointHostResolver::resolve(const string& host, int port, Ice::EndpointSelectionType selType, - const EndpointIPtr& endpoint) -{ - vector
addrs = - getAddresses(host, port, _instance->protocolSupport(), selType, _instance->preferIPv6(), false); - return endpoint->connectors(addrs, 0); -} - -void -IceInternal::EndpointHostResolver::resolve(const string&, int, - Ice::EndpointSelectionType selType, - const EndpointIPtr& endpoint, - const EndpointI_connectorsPtr& callback) -{ // - // No DNS lookup support with WinRT. + // Replace argument vector with only those we didn't recognize. // - callback->connectors(endpoint->connectors(selType)); -} - -void -IceInternal::EndpointHostResolver::destroy() -{ -} - -void -IceInternal::EndpointHostResolver::run() -{ + args = unknown; } -void -IceInternal::EndpointHostResolver::updateObserver() +bool +IceInternal::EndpointI::checkOption(const string&, const string&, const string&) { + // Must be overriden to check for options. + return false; } - -#endif -- cgit v1.2.3