Loading...
Searching...
No Matches
XrdClAsyncHSWriter.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_XRDCLASYNCHSWRITER_HH_
#define SRC_XRDCL_XRDCLASYNCHSWRITER_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 "XrdSys/XrdSysE2T.hh"
#include <memory>
namespace XrdCl
{
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
class AsyncHSWriter
{
public:
//------------------------------------------------------------------------
//------------------------------------------------------------------------
AsyncHSWriter( Socket &socket,
const std::string &strmname ) : writestage( WriteRequest ),
socket( socket ),
strmname( strmname ),
outmsg( nullptr )
{
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
inline void Reset( Message *msg = nullptr )
{
writestage = WriteRequest;
outmsg.reset( msg );
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
inline void Replay()
{
if( !outmsg ) return;
writestage = WriteRequest;
outmsg->SetCursor( 0 );
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
inline bool HasMsg()
{
return bool( outmsg );
}
//------------------------------------------------------------------------
//------------------------------------------------------------------------
XRootDStatus Write()
{
Log *log = DefaultEnv::GetLog();
while( true )
{
switch( writestage )
{
case WriteRequest:
{
XRootDStatus st = socket.Send( *outmsg, strmname );
if( !st.IsOK() || st.code == suRetry ) return st;
//----------------------------------------------------------------
// The next step is to write the signature
//----------------------------------------------------------------
writestage = WriteDone;
continue;
}
case WriteDone:
{
XRootDStatus st = socket.Flash();
if( !st.IsOK() )
{
log->Error( AsyncSockMsg, "[%s] Unable to flash the socket: %s",
strmname.c_str(), XrdSysE2T( st.errNo ) );
}
return st;
}
}
// just in case ...
break;
}
//----------------------------------------------------------------------
// We are done
//----------------------------------------------------------------------
return XRootDStatus();
}
private:
//------------------------------------------------------------------------
//------------------------------------------------------------------------
enum Stage
{
WriteRequest, //< the next step is to write the request
WriteDone //< the next step is to finalize the write
};
//------------------------------------------------------------------------
// Current read stage
//------------------------------------------------------------------------
Stage writestage;
//------------------------------------------------------------------------
// The context of the read operation
//------------------------------------------------------------------------
Socket &socket;
const std::string &strmname;
//------------------------------------------------------------------------
// The internal state of the the reader
//------------------------------------------------------------------------
std::unique_ptr<Message> outmsg;
};
}
#endif /* SRC_XRDCL_XRDCLASYNCHSWRITER_HH_ */
XrdClConstants.hh
XrdClMessage.hh
XrdClPostMasterInterfaces.hh
XrdClSocket.hh
XrdClStream.hh
XrdClXRootDResponses.hh
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
XrdSysE2T.hh
XrdCl::AsyncHSWriter::Replay
void Replay()
Replay the message that has been sent.
Definition XrdClAsyncHSWriter.hh:67
XrdCl::AsyncHSWriter::AsyncHSWriter
AsyncHSWriter(Socket &socket, const std::string &strmname)
Definition XrdClAsyncHSWriter.hh:47
XrdCl::AsyncHSWriter::HasMsg
bool HasMsg()
Check if writer was assigned with a message.
Definition XrdClAsyncHSWriter.hh:77
XrdCl::AsyncHSWriter::Write
XRootDStatus Write()
Write the request into the socket.
Definition XrdClAsyncHSWriter.hh:85
XrdCl::AsyncHSWriter::Reset
void Reset(Message *msg=nullptr)
Reset the state of the object (makes it ready to read out next msg).
Definition XrdClAsyncHSWriter.hh:58
XrdCl::DefaultEnv::GetLog
static Log * GetLog()
Get default log.
Definition XrdClDefaultEnv.cc:493
XrdCl::Log
Handle diagnostics.
Definition XrdClLog.hh:101
XrdCl::Log::Error
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition XrdClLog.cc:231
XrdCl::Message
The message representation used throughout the system.
Definition XrdClMessage.hh:32
XrdCl::Socket
A network socket.
Definition XrdClSocket.hh:43
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
XrdCl::Status::errNo
uint32_t errNo
Errno, if any.
Definition XrdClStatus.hh:148