xrootd
Loading...
Searching...
No Matches
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"
27#include "XrdCl/XrdClStream.hh"
28#include "XrdSys/XrdSysE2T.hh"
29
30#include <memory>
31
32
33namespace XrdCl
34{
35 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
39 {
40 public:
41 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
48 const std::string &strmname ) : writestage( WriteRequest ),
49 socket( socket ),
51 outmsg( nullptr )
52 {
53 }
54
55 //------------------------------------------------------------------------
57 //------------------------------------------------------------------------
58 inline void Reset( Message *msg = nullptr )
59 {
61 outmsg.reset( msg );
62 }
63
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
67 inline void Replay()
68 {
69 if( !outmsg ) return;
71 outmsg->SetCursor( 0 );
72 }
73
74 //------------------------------------------------------------------------
76 //------------------------------------------------------------------------
77 inline bool HasMsg()
78 {
79 return bool( outmsg );
80 }
81
82 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
86 {
87 Log *log = DefaultEnv::GetLog();
88 while( true )
89 {
90 switch( writestage )
91 {
92 case WriteRequest:
93 {
95 if( !st.IsOK() || st.code == suRetry ) return st;
96 //----------------------------------------------------------------
97 // The next step is to write the signature
98 //----------------------------------------------------------------
100 continue;
101 }
102
103 case WriteDone:
104 {
106 if( !st.IsOK() )
107 {
108 log->Error( AsyncSockMsg, "[%s] Unable to flash the socket: %s",
109 strmname.c_str(), XrdSysE2T( st.errNo ) );
110 }
111 return st;
112 }
113 }
114 // just in case ...
115 break;
116 }
117 //----------------------------------------------------------------------
118 // We are done
119 //----------------------------------------------------------------------
120 return XRootDStatus();
121 }
122
123 private:
124
125 //------------------------------------------------------------------------
127 //------------------------------------------------------------------------
128 enum Stage
129 {
130 WriteRequest, //< the next step is to write the request
131 WriteDone //< the next step is to finalize the write
132 };
133
134 //------------------------------------------------------------------------
135 // Current read stage
136 //------------------------------------------------------------------------
138
139 //------------------------------------------------------------------------
140 // The context of the read operation
141 //------------------------------------------------------------------------
143 const std::string &strmname;
144
145 //------------------------------------------------------------------------
146 // The internal state of the the reader
147 //------------------------------------------------------------------------
148 std::unique_ptr<Message> outmsg;
149 };
150}
151
152
153#endif /* SRC_XRDCL_XRDCLASYNCHSWRITER_HH_ */
const char * XrdSysE2T(int errcode)
Utility class encapsulating writing hand-shake request logic.
Definition XrdClAsyncHSWriter.hh:39
const std::string & strmname
Definition XrdClAsyncHSWriter.hh:143
void Replay()
Replay the message that has been sent.
Definition XrdClAsyncHSWriter.hh:67
AsyncHSWriter(Socket &socket, const std::string &strmname)
Definition XrdClAsyncHSWriter.hh:47
Stage
Stages of reading out a response from the socket.
Definition XrdClAsyncHSWriter.hh:129
@ WriteRequest
Definition XrdClAsyncHSWriter.hh:130
@ WriteDone
Definition XrdClAsyncHSWriter.hh:131
bool HasMsg()
Check if writer was assigned with a message.
Definition XrdClAsyncHSWriter.hh:77
XRootDStatus Write()
Write the request into the socket.
Definition XrdClAsyncHSWriter.hh:85
void Reset(Message *msg=nullptr)
Reset the state of the object (makes it ready to read out next msg)
Definition XrdClAsyncHSWriter.hh:58
Stage writestage
Definition XrdClAsyncHSWriter.hh:137
std::unique_ptr< Message > outmsg
Definition XrdClAsyncHSWriter.hh:148
Socket & socket
Definition XrdClAsyncHSWriter.hh:142
static Log * GetLog()
Get default log.
Handle diagnostics.
Definition XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
The message representation used throughout the system.
Definition XrdClMessage.hh:30
A network socket.
Definition XrdClSocket.hh:43
virtual XRootDStatus Send(const char *buffer, size_t size, int &bytesWritten)
XRootDStatus Flash()
Request status.
Definition XrdClXRootDResponses.hh:219
Definition XrdClAction.hh:34
const uint16_t suRetry
Definition XrdClStatus.hh:40
const uint64_t AsyncSockMsg
Definition XrdClConstants.hh:41
uint16_t code
Error type, or additional hints on what to do.
Definition XrdClStatus.hh:147
bool IsOK() const
We're fine.
Definition XrdClStatus.hh:124
uint32_t errNo
Errno, if any.
Definition XrdClStatus.hh:148