From ae3a0a79537b56f20e7a0366805b5a8656e56402 Mon Sep 17 00:00:00 2001
From: Michael Davis <michael.davis@cern.ch>
Date: Sun, 4 Jun 2017 03:29:35 +0200
Subject: [PATCH] Fixes XrdSsi receive metadata

---
 frontend/TestSsiRequest.cpp     | 31 +++++++++----------------------
 frontend/TestSsiRequest.h       | 29 +++++++++++++----------------
 frontend/TestSsiRequestProc.cpp |  1 +
 3 files changed, 23 insertions(+), 38 deletions(-)

diff --git a/frontend/TestSsiRequest.cpp b/frontend/TestSsiRequest.cpp
index 726d4fbbe5..f8d54cbe3b 100644
--- a/frontend/TestSsiRequest.cpp
+++ b/frontend/TestSsiRequest.cpp
@@ -10,14 +10,6 @@ bool TestSsiRequest::ProcessResponse(const XrdSsiErrInfo &eInfo, const XrdSsiRes
 
    cerr << "ProcessResponse() callback called with response type = " << rInfo.State() << endl;
 
-   // Resume handling callbacks if they were on hold
-
-   if(!queue_on_hold)
-   {
-      cerr << "resuming...";
-      this->RestartDataResponse(XrdSsiRequest::RDR_All);
-   }
-
    if (eInfo.hasError())
    {
       // Handle error using the passed eInfo object
@@ -42,19 +34,22 @@ bool TestSsiRequest::ProcessResponse(const XrdSsiErrInfo &eInfo, const XrdSsiRes
 
       GetMetadata(myMetadataLen);
 
-      if(rInfo.rType == XrdSsiRespInfo::isData && myMetadataLen == 0)
+      if(rInfo.rType == XrdSsiRespInfo::isData && myMetadataLen > 0)
       {
-         cerr << "Response is metadata only." << endl;
+         cerr << "Response has " << myMetadataLen << " bytes of metadata." << endl;
 
          // do something with metadata
 
+#if 0
          // clean up
 
          Finished();
 
          delete this;
+#endif
       }
-      else if(rInfo.rType == XrdSsiRespInfo::isHandle)
+
+      if(rInfo.rType == XrdSsiRespInfo::isHandle)
       {
          cerr << "Response is detached, handle = " << endl;
 
@@ -66,7 +61,8 @@ bool TestSsiRequest::ProcessResponse(const XrdSsiErrInfo &eInfo, const XrdSsiRes
 
          delete this;
       }
-      else
+
+      if(rInfo.rType == XrdSsiRespInfo::isData)
       {
          // A proper data response type
 
@@ -85,16 +81,7 @@ XrdSsiRequest::PRD_Xeq TestSsiRequest::ProcessResponseData(const XrdSsiErrInfo &
 {
    using namespace std;
 
-   // Simulate the scenario where we can't handle the queue at this time
-
-queue_on_hold = false;
-
-   if(queue_on_hold)
-   {
-      cerr << "Response queue is on hold...";
-      queue_on_hold = false;
-      return XrdSsiRequest::PRD_Hold;
-   }
+   // If we can't handle the queue at this time, return XrdSsiRequest::PRD_Hold;
 
    // GetResponseData() above places the data in the allocated buffer, then calls this method with
    // the buffer type and length
diff --git a/frontend/TestSsiRequest.h b/frontend/TestSsiRequest.h
index ffaa2eea4c..fcfa81399e 100644
--- a/frontend/TestSsiRequest.h
+++ b/frontend/TestSsiRequest.h
@@ -7,6 +7,16 @@ class TestSsiRequest : public XrdSsiRequest
 {
 public:
 
+           TestSsiRequest(const std::string &buffer_str, uint16_t tmo=0) : request_buffer(buffer_str.c_str()), request_len(buffer_str.length())
+           {
+              std::cerr << "Creating TestSsiRequest object, setting tmo=" << tmo << std::endl;
+              this->SetTimeOut(tmo);
+           }
+   virtual ~TestSsiRequest() 
+           {
+              std::cerr << "Deleting TestSsiRequest object" << std::endl;
+           }
+
    // It is up to the implementation to create request data, save it in some manner, and provide it to
    // the framework when GetRequest() is called. Optionally define the RelRequestBuffer() method to
    // clean up when the framework no longer needs access to the data.
@@ -15,7 +25,7 @@ public:
 
    // Query for Andy: shouldn't the return type for GetRequest be const?
 
-   virtual char *GetRequest(int &dlen) override {dlen = reqBLen; return const_cast<char*>(reqBuff);}
+   virtual char *GetRequest(int &reqlen) override { reqlen = request_len; return const_cast<char*>(request_buffer); }
 
    // Requests are sent to the server asynchronously via the service object. The ProcessResponse() callback
    // is used to inform the request object if the request completed or failed.
@@ -33,23 +43,10 @@ public:
 
    virtual void Alert(XrdSsiRespInfoMsg &aMsg) override;
 
-   // Constructor/Destructor
-
-                 TestSsiRequest(const std::string &buffer_str, uint16_t tmo=0) : reqBuff(buffer_str.c_str()), reqBLen(buffer_str.length()), queue_on_hold(true)
-                 {
-                    std::cerr << "Creating TestSsiRequest object, setting tmo=" << tmo << std::endl;
-                    this->SetTimeOut(tmo);
-                 }
-   virtual      ~TestSsiRequest() 
-                 {
-                    std::cerr << "Deleting TestSsiRequest object" << std::endl;
-                 }
-
 private:
 
-   const char *reqBuff;
-   int   reqBLen;
-   bool  queue_on_hold;
+   const char *request_buffer;
+   int         request_len;
 };
 
 #endif
diff --git a/frontend/TestSsiRequestProc.cpp b/frontend/TestSsiRequestProc.cpp
index 67f7d072eb..c5675946e9 100644
--- a/frontend/TestSsiRequestProc.cpp
+++ b/frontend/TestSsiRequestProc.cpp
@@ -30,6 +30,7 @@ void RequestProc<xrdssi::test::Request, xrdssi::test::Result>::ExecuteAction()
 template <>
 void RequestProc<xrdssi::test::Request, xrdssi::test::Result>::ExecuteMetadata()
 {
+   std::cerr << "Sending metadata..." << std::endl;
    const std::string metadata("Have some metadata!");
    SetMetadata(metadata.c_str(), metadata.size());
 }
-- 
GitLab