diff --git a/src/XrdCl/XrdClChannel.cc b/src/XrdCl/XrdClChannel.cc index d2be5cd704f..5f6b0efa3b9 100644 --- a/src/XrdCl/XrdClChannel.cc +++ b/src/XrdCl/XrdClChannel.cc @@ -170,6 +170,15 @@ namespace XrdCl return Status(); } + //---------------------------------------------------------------------------- + // Force reconnect + //---------------------------------------------------------------------------- + Status Channel::ForceReconnect() + { + pStream->ForceConnect(); + return Status(); + } + //------------------------------------------------------------------------ // Get the number of connected data streams //------------------------------------------------------------------------ diff --git a/src/XrdCl/XrdClChannel.hh b/src/XrdCl/XrdClChannel.hh index 0bd9474822e..d1668f04677 100644 --- a/src/XrdCl/XrdClChannel.hh +++ b/src/XrdCl/XrdClChannel.hh @@ -125,6 +125,11 @@ namespace XrdCl //------------------------------------------------------------------------ Status ForceDisconnect(); + //------------------------------------------------------------------------ + //! Force reconnect + //------------------------------------------------------------------------ + Status ForceReconnect(); + //------------------------------------------------------------------------ //! Get the number of connected data streams //------------------------------------------------------------------------ diff --git a/src/XrdCl/XrdClPostMaster.cc b/src/XrdCl/XrdClPostMaster.cc index 15facb33878..7b860c3c18c 100644 --- a/src/XrdCl/XrdClPostMaster.cc +++ b/src/XrdCl/XrdClPostMaster.cc @@ -245,7 +245,11 @@ namespace XrdCl AnyObject &result ) { XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock ); - Channel *channel = GetChannel( url ); + PostMasterImpl::ChannelMap::iterator it = + pImpl->pChannelMap.find( url.GetChannelId() ); + if( it == pImpl->pChannelMap.end() ) + return Status( stError, errInvalidOp ); + Channel *channel = it->second; if( !channel ) return Status( stError, errNotSupported ); @@ -320,6 +324,19 @@ namespace XrdCl return Status(); } + Status PostMaster::ForceReconnect( const URL &url ) + { + XrdSysRWLockHelper scopedLock( pImpl->pDisconnectLock, false ); + PostMasterImpl::ChannelMap::iterator it = + pImpl->pChannelMap.find( url.GetChannelId() ); + + if( it == pImpl->pChannelMap.end() ) + return Status( stError, errInvalidOp ); + + it->second->ForceReconnect(); + return Status(); + } + //------------------------------------------------------------------------ // Get the number of connected data streams //------------------------------------------------------------------------ diff --git a/src/XrdCl/XrdClPostMaster.hh b/src/XrdCl/XrdClPostMaster.hh index 89050ca195a..3ba59e2759a 100644 --- a/src/XrdCl/XrdClPostMaster.hh +++ b/src/XrdCl/XrdClPostMaster.hh @@ -152,6 +152,11 @@ namespace XrdCl //------------------------------------------------------------------------ Status ForceDisconnect( const URL &url ); + //------------------------------------------------------------------------ + //! Reconnect the channel + //------------------------------------------------------------------------ + Status ForceReconnect( const URL &url ); + //------------------------------------------------------------------------ //! Get the number of connected data streams //------------------------------------------------------------------------ diff --git a/src/XrdCl/XrdClStream.cc b/src/XrdCl/XrdClStream.cc index cb64cbb6bc6..b3c4466da35 100644 --- a/src/XrdCl/XrdClStream.cc +++ b/src/XrdCl/XrdClStream.cc @@ -347,11 +347,14 @@ namespace XrdCl void Stream::ForceConnect() { XrdSysMutexHelper scopedLock( pMutex ); - pSubStreams[0]->status = Socket::Disconnected; - XrdCl::PathID path( 0, 0 ); - XrdCl::XRootDStatus st = EnableLink( path ); - if( !st.IsOK() ) - OnConnectError( 0, st ); + if( pSubStreams[0]->status == Socket::Connecting ) + { + pSubStreams[0]->status = Socket::Disconnected; + XrdCl::PathID path( 0, 0 ); + XrdCl::XRootDStatus st = EnableLink( path ); + if( !st.IsOK() ) + OnConnectError( 0, st ); + } } //---------------------------------------------------------------------------- @@ -399,11 +402,11 @@ namespace //------------------------------------------------------------------------ // Constructor //------------------------------------------------------------------------ - StreamConnectorTask( XrdCl::Stream *stream ): - pStream( stream ) + StreamConnectorTask( const XrdCl::URL &url, const std::string &n ): + url( url ) { std::string name = "StreamConnectorTask for "; - name += stream->GetName(); + name += n; SetName( name ); } @@ -412,12 +415,12 @@ namespace //------------------------------------------------------------------------ time_t Run( time_t ) { - pStream->ForceConnect(); + XrdCl::DefaultEnv::GetPostMaster()->ForceReconnect( url ); return 0; } private: - XrdCl::Stream *pStream; + XrdCl::URL url; }; } @@ -775,7 +778,7 @@ namespace XrdCl log->Info( PostMasterMsg, "[%s] Attempting reconnection in %d " "seconds.", pStreamName.c_str(), pConnectionWindow-elapsed ); - Task *task = new ::StreamConnectorTask( this ); + Task *task = new ::StreamConnectorTask( *pUrl, pStreamName ); pTaskManager->RegisterTask( task, pConnectionInitTime+pConnectionWindow ); return; }