Loading...
Searching...
No Matches
XrdClAsyncHSReader.hh
Go to the documentation of this file.
//------------------------------------------------------------------------------
// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
// Author: Michal Simon <michal.simon@cern.ch>
//------------------------------------------------------------------------------
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------
#ifndef SRC_XRDCL_XRDCLASYNCHSREADER_HH_
#define SRC_XRDCL_XRDCLASYNCHSREADER_HH_
#include "XrdCl/XrdClMessage.hh"
#include "XrdCl/XrdClPostMasterInterfaces.hh"
#include "XrdCl/XrdClXRootDResponses.hh"
#include "XrdCl/XrdClSocket.hh"
#include "XrdCl/XrdClConstants.hh"
#include "XrdCl/XrdClStream.hh"
#include <memory>
namespace XrdCl
{
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class AsyncHSReader
{
public:
//------------------------------------------------------------------------
//------------------------------------------------------------------------
AsyncHSReader( TransportHandler &xrdTransport,
Socket &socket,
const std::string &strmname,
Stream &strm,
uint16_t substrmnb) : readstage( ReadStart ),
xrdTransport( xrdTransport ),
socket( socket ),
strmname( strmname ),
strm( strm ),
substrmnb( substrmnb )
{
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
XRootDStatus Read()
{
Log *log = DefaultEnv::GetLog();
while( true )
{
switch( readstage )
{
//------------------------------------------------------------------
// There is no incoming message currently being processed so we
// create a new one
//------------------------------------------------------------------
case ReadStart:
{
inmsg.reset( new Message() );
//----------------------------------------------------------------
// The next step is to read the header
//----------------------------------------------------------------
readstage = ReadHeader;
continue;
}
//------------------------------------------------------------------
// We need to read the header
//------------------------------------------------------------------
case ReadHeader:
{
XRootDStatus st = xrdTransport.GetHeader( *inmsg, &socket );
if( !st.IsOK() || st.code == suRetry ) return st;
log->Dump( AsyncSockMsg,
"[%s] Received message header, size: %d",
strmname.c_str(), inmsg->GetCursor() );
//----------------------------------------------------------------
// The next step is to read the message body
//----------------------------------------------------------------
readstage = ReadMsgBody;
continue;
}
//------------------------------------------------------------------
// We read the message to the buffer
//------------------------------------------------------------------
case ReadMsgBody:
{
XRootDStatus st = xrdTransport.GetBody( *inmsg, &socket );
if( !st.IsOK() || st.code == suRetry ) return st;
log->Dump( AsyncSockMsg, "[%s] Received a message of %d bytes",
strmname.c_str(), inmsg->GetSize() );
readstage = ReadDone;
return st;
}
case ReadDone: return XRootDStatus();
}
// just in case ...
break;
}
//----------------------------------------------------------------------
// We are done
//----------------------------------------------------------------------
return XRootDStatus();
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
std::unique_ptr<Message> ReleaseMsg()
{
readstage = ReadStart;
return std::move( inmsg );
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
inline void Reset()
{
readstage = ReadStart;
inmsg.reset();
}
private:
//------------------------------------------------------------------------
//------------------------------------------------------------------------
enum Stage
{
ReadStart, //< the next step is to initialize the read
ReadHeader, //< the next step is to read the header
ReadMsgBody, //< the next step is to read the body
ReadDone //< we are done
};
//------------------------------------------------------------------------
// Current read stage
//------------------------------------------------------------------------
Stage readstage;
//------------------------------------------------------------------------
// The context of the read operation
//------------------------------------------------------------------------
TransportHandler &xrdTransport;
Socket &socket;
const std::string &strmname;
Stream &strm;
uint16_t substrmnb;
//------------------------------------------------------------------------
// The internal state of the the reader
//------------------------------------------------------------------------
std::unique_ptr<Message> inmsg;
};
}
#endif /* SRC_XRDCL_XRDCLASYNCHSREADER_HH_ */
XrdClConstants.hh
XrdClMessage.hh
XrdClPostMasterInterfaces.hh
XrdClSocket.hh
XrdClStream.hh
XrdClXRootDResponses.hh
XrdCl::AsyncHSReader::Reset
void Reset()
Reset the state of the object (makes it ready to read out next msg).
Definition XrdClAsyncHSReader.hh:137
XrdCl::AsyncHSReader::AsyncHSReader
AsyncHSReader(TransportHandler &xrdTransport, Socket &socket, const std::string &strmname, Stream &strm, uint16_t substrmnb)
Definition XrdClAsyncHSReader.hh:48
XrdCl::AsyncHSReader::ReleaseMsg
std::unique_ptr< Message > ReleaseMsg()
Transfer the received message ownership.
Definition XrdClAsyncHSReader.hh:128
XrdCl::AsyncHSReader::Read
XRootDStatus Read()
Read out the response from the socket.
Definition XrdClAsyncHSReader.hh:64
XrdCl::DefaultEnv::GetLog
static Log * GetLog()
Get default log.
Definition XrdClDefaultEnv.cc:493
XrdCl::Log
Handle diagnostics.
Definition XrdClLog.hh:101
XrdCl::Log::Dump
void Dump(uint64_t topic, const char *format,...)
Print a dump message.
Definition XrdClLog.cc:299
XrdCl::Message
The message representation used throughout the system.
Definition XrdClMessage.hh:32
XrdCl::Socket
A network socket.
Definition XrdClSocket.hh:43
XrdCl::Stream
Stream.
Definition XrdClStream.hh:52
XrdCl::TransportHandler
Perform the handshake and the authentication for each physical stream.
Definition XrdClPostMasterInterfaces.hh:310
XrdCl::XRootDStatus
Request status.
Definition XrdClXRootDResponses.hh:219
XrdCl
Definition XrdClAction.hh:34
XrdCl::suRetry
const uint16_t suRetry
Definition XrdClStatus.hh:40
XrdCl::AsyncSockMsg
const uint64_t AsyncSockMsg
Definition XrdClConstants.hh:41
XrdCl::Status::code
uint16_t code
Error type, or additional hints on what to do.
Definition XrdClStatus.hh:147
XrdCl::Status::IsOK
bool IsOK() const
We're fine.
Definition XrdClStatus.hh:124