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 ),
50 strmname( strmname ),
51 outmsg( nullptr )
52 {
53 }
54
55 //------------------------------------------------------------------------
57 //------------------------------------------------------------------------
58 inline void Reset( Message *msg = nullptr )
59 {
60 writestage = WriteRequest;
61 outmsg.reset( msg );
62 }
63
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
67 inline void Replay()
68 {
69 if( !outmsg ) return;
70 writestage = WriteRequest;
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 {
94 XRootDStatus st = socket.Send( *outmsg, strmname );
95 if( !st.IsOK() || st.code == suRetry ) return st;
96 //----------------------------------------------------------------
97 // The next step is to write the signature
98 //----------------------------------------------------------------
99 writestage = WriteDone;
100 continue;
101 }
102
103 case WriteDone:
104 {
105 XRootDStatus st = socket.Flash();
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 //------------------------------------------------------------------------
137 Stage writestage;
138
139 //------------------------------------------------------------------------
140 // The context of the read operation
141 //------------------------------------------------------------------------
142 Socket &socket;
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)
Definition XrdSysE2T.cc:104
void Replay()
Replay the message that has been sent.
AsyncHSWriter(Socket &socket, const std::string &strmname)
bool HasMsg()
Check if writer was assigned with a message.
XRootDStatus Write()
Write the request into the socket.
void Reset(Message *msg=nullptr)
Reset the state of the object (makes it ready to read out next msg)
static Log * GetLog()
Get default log.
Handle diagnostics.
Definition XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition XrdClLog.cc:231
The message representation used throughout the system.
A network socket.
const uint16_t suRetry
const uint64_t AsyncSockMsg
uint16_t code
Error type, or additional hints on what to do.
bool IsOK() const
We're fine.
uint32_t errNo
Errno, if any.