xrootd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XrdClAsyncHSWriter.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Michal Simon <michal.simon@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef SRC_XRDCL_XRDCLASYNCHSWRITER_HH_
20 #define SRC_XRDCL_XRDCLASYNCHSWRITER_HH_
21 
22 #include "XrdCl/XrdClMessage.hh"
25 #include "XrdCl/XrdClSocket.hh"
26 #include "XrdCl/XrdClConstants.hh"
27 #include "XrdCl/XrdClStream.hh"
28 #include "XrdSys/XrdSysE2T.hh"
29 
30 #include <memory>
31 
32 
33 namespace XrdCl
34 {
35  //----------------------------------------------------------------------------
37  //----------------------------------------------------------------------------
39  {
40  public:
41  //------------------------------------------------------------------------
47  //------------------------------------------------------------------------
49  const std::string &strmname ) : writestage( WriteRequest ),
50  socket( socket ),
51  strmname( strmname ),
52  outmsg( nullptr )
53  {
54  }
55 
56  //------------------------------------------------------------------------
58  //------------------------------------------------------------------------
59  inline void Reset( Message *msg = nullptr )
60  {
62  outmsg.reset( msg );
63  }
64 
65  //------------------------------------------------------------------------
67  //------------------------------------------------------------------------
68  inline void Replay()
69  {
70  if( !outmsg ) return;
72  outmsg->SetCursor( 0 );
73  }
74 
75  //------------------------------------------------------------------------
77  //------------------------------------------------------------------------
78  inline bool HasMsg()
79  {
80  return bool( outmsg );
81  }
82 
83  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
87  {
88  Log *log = DefaultEnv::GetLog();
89  while( true )
90  {
91  switch( writestage )
92  {
93  case WriteRequest:
94  {
96  if( !st.IsOK() || st.code == suRetry ) return st;
97  //----------------------------------------------------------------
98  // The next step is to write the signature
99  //----------------------------------------------------------------
101  continue;
102  }
103 
104  case WriteDone:
105  {
106  XRootDStatus st = socket.Flash();
107  if( !st.IsOK() )
108  {
109  log->Error( AsyncSockMsg, "[%s] Unable to flash the socket: %s",
110  strmname.c_str(), XrdSysE2T( st.errNo ) );
111  }
112  return st;
113  }
114  }
115  // just in case ...
116  break;
117  }
118  //----------------------------------------------------------------------
119  // We are done
120  //----------------------------------------------------------------------
121  return XRootDStatus();
122  }
123 
124  private:
125 
126  //------------------------------------------------------------------------
128  //------------------------------------------------------------------------
129  enum Stage
130  {
131  WriteRequest, //< the next step is to write the request
132  WriteDone //< the next step is to finalize the write
133  };
134 
135  //------------------------------------------------------------------------
136  // Current read stage
137  //------------------------------------------------------------------------
139 
140  //------------------------------------------------------------------------
141  // The context of the read operation
142  //------------------------------------------------------------------------
144  const std::string &strmname;
145 
146  //------------------------------------------------------------------------
147  // The internal state of the the reader
148  //------------------------------------------------------------------------
149  std::unique_ptr<Message> outmsg;
150  };
151 }
152 
153 
154 #endif /* SRC_XRDCL_XRDCLASYNCHSWRITER_HH_ */
XRootDStatus Write()
Write the request into the socket.
Definition: XrdClAsyncHSWriter.hh:86
void Reset(Message *msg=nullptr)
Reset the state of the object (makes it ready to read out next msg)
Definition: XrdClAsyncHSWriter.hh:59
Socket & socket
Definition: XrdClAsyncHSWriter.hh:143
The message representation used throughout the system.
Definition: XrdClMessage.hh:29
const uint64_t AsyncSockMsg
Definition: XrdClConstants.hh:41
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:146
Utility class encapsulating writing hand-shake request logic.
Definition: XrdClAsyncHSWriter.hh:38
XRootDStatus Flash()
static Log * GetLog()
Get default log.
void Replay()
Replay the message that has been sent.
Definition: XrdClAsyncHSWriter.hh:68
Stage writestage
Definition: XrdClAsyncHSWriter.hh:138
Definition: XrdClAsyncHSWriter.hh:132
std::unique_ptr< Message > outmsg
Definition: XrdClAsyncHSWriter.hh:149
Request status.
Definition: XrdClXRootDResponses.hh:218
bool HasMsg()
Check if writer was assigned with a message.
Definition: XrdClAsyncHSWriter.hh:78
const char * XrdSysE2T(int errcode)
void Error(uint64_t topic, const char *format,...)
Report an error.
uint32_t errNo
Errno, if any.
Definition: XrdClStatus.hh:147
const std::string & strmname
Definition: XrdClAsyncHSWriter.hh:144
const uint16_t suRetry
Definition: XrdClStatus.hh:40
AsyncHSWriter(Socket &socket, const std::string &strmname)
Definition: XrdClAsyncHSWriter.hh:48
bool IsOK() const
We&#39;re fine.
Definition: XrdClStatus.hh:123
Stage
Stages of reading out a response from the socket.
Definition: XrdClAsyncHSWriter.hh:129
Definition: XrdClAsyncHSWriter.hh:131
A network socket.
Definition: XrdClSocket.hh:42
Handle diagnostics.
Definition: XrdClLog.hh:100
XRootDStatus Send(const char *buffer, size_t size, int &bytesWritten)