XRootD
XrdSsiResponder Class Referenceabstract

#include <XrdSsiResponder.hh>

+ Inheritance diagram for XrdSsiResponder:
+ Collaboration diagram for XrdSsiResponder:

Public Member Functions

void BindRequest (XrdSsiRequest &rqstR)
 
bool UnBindRequest ()
 

Static Public Attributes

static const int MaxDirectXfr = 2097152
 

Protected Types

enum  Status {
  wasPosted =0 ,
  notPosted ,
  notActive
}
 

Protected Member Functions

 XrdSsiResponder ()
 
virtual ~XrdSsiResponder ()
 
void Alert (XrdSsiRespInfoMsg &aMsg)
 
virtual void Finished (XrdSsiRequest &rqstR, const XrdSsiRespInfo &rInfo, bool cancel=false)=0
 
char * GetRequest (int &dlen)
 
void ReleaseRequestBuffer ()
 
Status SetErrResponse (const char *eMsg, int eNum)
 
Status SetMetadata (const char *buff, int blen)
 
Status SetNilResponse ()
 
Status SetResponse (const char *buff, int blen)
 
Status SetResponse (long long fsize, int fdnum)
 
Status SetResponse (XrdSsiStream *strmP)
 

Static Protected Attributes

static const int MaxMetaDataSZ = 2097152
 2MB metadata limit More...
 

Friends

class XrdSsiRequest
 
class XrdSsiRRAgent
 

Detailed Description

Definition at line 68 of file XrdSsiResponder.hh.

Member Enumeration Documentation

◆ Status

enum XrdSsiResponder::Status
protected

The following enums are returned by SetMetadata() and SetResponse() to indicate ending status.

Enumerator
wasPosted 

Success: The response was successfully posted.

notPosted 

Failure: A request was not bound to this object or a response has already been posted or the metadata length was invalid

notActive 

Failure: Request is no longer active.

Definition at line 162 of file XrdSsiResponder.hh.

162  {wasPosted=0,
163  notPosted,
166  notActive
167  };
@ notActive
Failure: Request is no longer active.
@ wasPosted
Success: The response was successfully posted.

Constructor & Destructor Documentation

◆ XrdSsiResponder()

XrdSsiResponder::XrdSsiResponder ( )
protected

This class is meant to be inherited by an object that will actually posts responses.

Definition at line 96 of file XrdSsiResponder.cc.

97  : spMutex(XrdSsiMutex::Recursive), reqP(0),
98  rsvd1(0), rsvd2(0), rsvd3(0)
99  {}

◆ ~XrdSsiResponder()

XrdSsiResponder::~XrdSsiResponder ( )
protectedvirtual

Destructor is protected. You cannot use delete on a responder object, as it is meant to be inherited by a class and not separately instantiated.

Definition at line 105 of file XrdSsiResponder.cc.

106 {
107 // Lock ourselves (unlikely that we need to).
108 //
109  spMutex.Lock();
110 
111 // If we haven't taken a trip to Finished() then we need todo it here. The
112 // issue we have is that this object may be deleted before Finished() is called
113 // which is quite dicey. So, we defer it until Finished() is called. This is
114 // only an issue server-side as we don't control the finish process.
115 //
116  if (reqP)
117  {reqP->rrMutex->Lock();
118  if (reqP->theRespond == this)
119  {reqP->theRespond = &ForceUnBind;
120  reqP->rrMutex->UnLock();
121  } else if (reqP->theRespond == 0) // Finish() has been called
122  {reqP->rrMutex->UnLock();
123  reqP->Dispose();
124  }
125  }
126 
127 // All done
128 //
129  spMutex.UnLock();
130 }

References XrdSsiMutex::Lock(), and XrdSsiMutex::UnLock().

+ Here is the call graph for this function:

Member Function Documentation

◆ Alert()

void XrdSsiResponder::Alert ( XrdSsiRespInfoMsg aMsg)
protected

Send an alert message to the request. This is a convenience method that avoids race conditions with Finished() so it is safe to use in all cases. This is a server-side call. The service is responsible for creating a RespInfoMsg object containing the message and supplying a RecycleMsg() method.

Parameters
aMsgreference to the message to be sent.

Definition at line 136 of file XrdSsiResponder.cc.

137 {
138  XrdSsiMutexMon lck(spMutex);
139 
140 // If we have a request pointer then forward the alert. Otherwise, deep-six it
141 //
142  if (reqP) reqP->Alert(aMsg);
143  else aMsg.RecycleMsg(false);
144 }
virtual void Alert(XrdSsiRespInfoMsg &aMsg)
Send or receive a server generated alert.
virtual void RecycleMsg(bool sent=true)=0

References XrdSsiRequest::Alert(), and XrdSsiRespInfoMsg::RecycleMsg().

+ Here is the call graph for this function:

◆ BindRequest()

void XrdSsiResponder::BindRequest ( XrdSsiRequest rqstR)

Take ownership of a request object by binding the request object to a responder object. This method must be called by the responder before posting any responses.

Parameters
rqstRreference to the request object.

Definition at line 150 of file XrdSsiResponder.cc.

151 {
152  XrdSsiMutexMon lck(spMutex);
153 
154 // Get the request lock and link the request to this object and vice versa
155 //
156  rqstR.rrMutex->Lock();
157  reqP = &rqstR;
158  rqstR.theRespond = this;
159 
160 // Initialize the request object
161 //
162  rqstR.Resp.Init();
163  rqstR.errInfo.Clr();
164 
165 // Notify the request that the bind comleted (this is only used on the
166 // server to allow a pending finish request to be sent to the responder).
167 //
168  rqstR.BindDone();
169 
170 // Unlock the request. The responder is unlocked upon return
171 //
172  rqstR.rrMutex->UnLock();
173 }
void Clr()
Reset and clear error information.

References XrdSsiErrInfo::Clr(), XrdSsiRespInfo::Init(), XrdSsiMutex::Lock(), and XrdSsiMutex::UnLock().

+ Here is the call graph for this function:

◆ Finished()

virtual void XrdSsiResponder::Finished ( XrdSsiRequest rqstR,
const XrdSsiRespInfo rInfo,
bool  cancel = false 
)
protectedpure virtual

Notify the responder that a request either completed or was canceled. This allows the responder to release any resources given to the request object (e.g. data response buffer or a stream). This method is invoked when XrdSsiRequest::Finished() is called by the client.

Parameters
rqstRreference to the object describing the request.
rInforeference to the object describing the response.
cancelFalse -> the request/response interaction completed. True -> the request/response interaction aborted because of an error or the client requested that the request be canceled.

Implemented in PostError, and XrdSsiTaskReal.

Referenced by XrdSsiRequest::Finished().

+ Here is the caller graph for this function:

◆ GetRequest()

char * XrdSsiResponder::GetRequest ( int &  dlen)
protected

Obtain the request data sent by a client.

Note: This method is called with the object's recursive mutex unlocked!

Parameters
dlenholds the length of the request after the call.
Returns
=0 No request data available, dlen has been set to zero.
!0 Pointer to the buffer holding the request, dlen has the length

Definition at line 179 of file XrdSsiResponder.cc.

180 {
181  XrdSsiMutexMon lck(spMutex);
182 
183 // If we have a request pointer, forward the call. Otherwise return nothing.
184 //
185  if (reqP) return reqP->GetRequest(dlen);
186  dlen = 0;
187  return 0;
188 }
virtual char * GetRequest(int &dlen)=0

References XrdSsiRequest::GetRequest().

+ Here is the call graph for this function:

◆ ReleaseRequestBuffer()

void XrdSsiResponder::ReleaseRequestBuffer ( )
protected

Release the request buffer of the request bound to this object. This method duplicates the protected method of the same name in XrdSsiRequest and exists here for calling safety and consistency relative to the responder.

Definition at line 194 of file XrdSsiResponder.cc.

195 {
196  XrdSsiMutexMon lck(spMutex);
197 
198 // If we have a request, forward the call (note we need to also get the
199 // the request lock to properly serialize this call).
200 //
201  if (reqP) reqP->ReleaseRequestBuffer();
202 }
void ReleaseRequestBuffer()

References XrdSsiRequest::ReleaseRequestBuffer().

+ Here is the call graph for this function:

◆ SetErrResponse()

XrdSsiResponder::Status XrdSsiResponder::SetErrResponse ( const char *  eMsg,
int  eNum 
)
protected

Set an error response for a request.

Parameters
eMsgthe message describing the error. The message is copied to private storage.
eNumthe errno associated with the error.
Returns
See Status enum for possible values.

Definition at line 229 of file XrdSsiResponder.cc.

231 {
232 
233 // Validate object for a response
234 //
236 
237 // Set the error response (we have the right locks now)
238 //
239  reqP->errInfo.Set(eMsg, eNum);
240  reqP->Resp.eMsg = reqP->errInfo.Get(reqP->Resp.eNum).c_str();
241  reqP->Resp.rType = XrdSsiRespInfo::isError;
242 
243 // Complete the response
244 //
246 }
#define eMsg(x)
#define SSI_XEQ_RESPONSE
#define SSI_VAL_RESPONSE
void Set(const char *eMsg=0, int eNum=0, int eArg=0)
const std::string & Get(int &eNum) const

References eMsg, XrdSsiErrInfo::Get(), XrdSsiRespInfo::isError, XrdSsiRespInfo::rType, XrdSsiErrInfo::Set(), SSI_VAL_RESPONSE, and SSI_XEQ_RESPONSE.

+ Here is the call graph for this function:

◆ SetMetadata()

XrdSsiResponder::Status XrdSsiResponder::SetMetadata ( const char *  buff,
int  blen 
)
protected

Definition at line 208 of file XrdSsiResponder.cc.

209 {
210  XrdSsiMutexMon lck(spMutex);
211 
212 // If we don't have a request or the args are invalid, return an error.
213 //
214  if (!reqP || blen < 0 || blen > MaxMetaDataSZ) return notPosted;
215 
216 // Post the metadata
217 //
218  reqP->rrMutex->Lock();
219  reqP->Resp.mdata = buff;
220  reqP->Resp.mdlen = blen;
221  reqP->rrMutex->UnLock();
222  return wasPosted;
223 }
static const int MaxMetaDataSZ
2MB metadata limit
int mdlen
Metadata length.
const char * mdata
-> Metadata about response.

References XrdSsiMutex::Lock(), MaxMetaDataSZ, XrdSsiRespInfo::mdata, XrdSsiRespInfo::mdlen, notPosted, XrdSsiMutex::UnLock(), and wasPosted.

+ Here is the call graph for this function:

◆ SetNilResponse()

Status XrdSsiResponder::SetNilResponse ( )
inlineprotected

Set a nil response for a request (used for sending only metadata).

Returns
See Status enum for possible values.

Definition at line 202 of file XrdSsiResponder.hh.

202 {return SetResponse((const char *)0,0);}
Status SetResponse(const char *buff, int blen)

References SetResponse().

+ Here is the call graph for this function:

◆ SetResponse() [1/3]

XrdSsiResponder::Status XrdSsiResponder::SetResponse ( const char *  buff,
int  blen 
)
protected

Set a memory buffer containing data as the request response.

Parameters
buffpointer to a buffer holding the response. The buffer must remain valid until XrdSsiResponder::Finished() is called.
blenthe length of the response in buff that is to be sent.
Returns
See Status enum for possible values.

Definition at line 252 of file XrdSsiResponder.cc.

253 {
254 
255 // Validate object for a response
256 //
258 
259 // Set the response (we have the right locks now)
260 //
261  reqP->Resp.buff = buff;
262  reqP->Resp.blen = blen;
263  reqP->Resp.rType = XrdSsiRespInfo::isData;
264 
265 // Complete the response
266 //
268 }

References XrdSsiRespInfo::isData, XrdSsiRespInfo::rType, SSI_VAL_RESPONSE, and SSI_XEQ_RESPONSE.

Referenced by SetNilResponse().

+ Here is the caller graph for this function:

◆ SetResponse() [2/3]

XrdSsiResponder::Status XrdSsiResponder::SetResponse ( long long  fsize,
int  fdnum 
)
protected

Set a file containing data as the response.

Parameters
fsizethe size of the file containing the response.
fdnumthe file descriptor of the open file.
Returns
See Status enum for possible values.

Definition at line 272 of file XrdSsiResponder.cc.

273 {
274 
275 // Validate object for a response
276 //
278 
279 // Set the response (we have the right locks now)
280 //
281  reqP->Resp.fdnum = fdnum;
282  reqP->Resp.fsize = fsize;
283  reqP->Resp.rType = XrdSsiRespInfo::isFile;
284 
285 // Complete the response
286 //
288 }

References XrdSsiRespInfo::isFile, XrdSsiRespInfo::rType, SSI_VAL_RESPONSE, and SSI_XEQ_RESPONSE.

◆ SetResponse() [3/3]

XrdSsiResponder::Status XrdSsiResponder::SetResponse ( XrdSsiStream strmP)
protected

Set a stream object that is to provide data as the response.

Parameters
strmPpointer to stream object that is to be used to supply response data. See XrdSsiStream for more details.
Returns
See Status enum for possible values.

Definition at line 292 of file XrdSsiResponder.cc.

293 {
294 
295 // Validate object for a response
296 //
298 
299 // Set the response (we have the right locks now)
300 //
301  reqP->Resp.eNum = 0;
302  reqP->Resp.strmP = strmP;
303  reqP->Resp.rType = XrdSsiRespInfo::isStream;
304 
305 // Complete the response
306 //
308 }

References XrdSsiRespInfo::isStream, XrdSsiRespInfo::rType, SSI_VAL_RESPONSE, and SSI_XEQ_RESPONSE.

◆ UnBindRequest()

bool XrdSsiResponder::UnBindRequest ( )

Unbind this responder from the request object it is bound to. Upon return ownership of the associated request object reverts back to the creator of the object who is responsible for deleting or recycling the request object. UnBindRequest() is also called when the responder object is deleted.

Returns
true Request successfully unbound. false UnBindRequest already called or called prior to Finish().

Definition at line 314 of file XrdSsiResponder.cc.

315 {
316  XrdSsiMutexMon spMon(spMutex);
317 
318 // If we are not bound to a request, indicate an error.
319 //
320  if (!reqP) return false;
321 
322 // Lock the request and if Finished() was not called, indicate an error.
323 //
324  reqP->rrMutex->Lock();
325  if (reqP->theRespond != 0)
326  {reqP->rrMutex->UnLock();
327  return false;
328  }
329 
330 // We have a request pointer and Finish() was called; so do the actual unbind.
331 //
332  reqP->rrMutex->UnLock();
333  reqP->Dispose();
334  reqP = 0;
335  return true;
336 }

References XrdSsiMutex::Lock(), and XrdSsiMutex::UnLock().

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ XrdSsiRequest

friend class XrdSsiRequest
friend

Definition at line 71 of file XrdSsiResponder.hh.

◆ XrdSsiRRAgent

friend class XrdSsiRRAgent
friend

Definition at line 72 of file XrdSsiResponder.hh.

Member Data Documentation

◆ MaxDirectXfr

const int XrdSsiResponder::MaxDirectXfr = 2097152
static

The maximum amount of metadata+data (i.e. the sum of two blen arguments in SetMetadata() and and SetResponse(const char *buff, int blen), respectively) that may be directly sent to the client without the SSI framework converting the data buffer response into a stream response.

Definition at line 81 of file XrdSsiResponder.hh.

Referenced by XrdSsiFileSess::AttnInfo().

◆ MaxMetaDataSZ

const int XrdSsiResponder::MaxMetaDataSZ = 2097152
staticprotected

2MB metadata limit

Set a pointer to metadata to be sent out-of-band ahead of the response.

Parameters
buffpointer to a buffer holding the metadata. The buffer must remain valid until XrdSsiResponder::Finished() is called.
blenthe length of the metadata in buff that is to be sent. It must in the range 0 <= blen <= MaxMetaDataSZ.
Returns
See Status enum for possible values.

Definition at line 180 of file XrdSsiResponder.hh.

Referenced by SetMetadata().


The documentation for this class was generated from the following files: