From 5ed9f464691b4056ae9c713578767dc3efc98663 Mon Sep 17 00:00:00 2001
From: Fons Rademakers <Fons.Rademakers@cern.ch>
Date: Mon, 21 Aug 2000 10:37:30 +0000
Subject: [PATCH] added new method TMessage::Forward() which allows a just
 received message to be send out (forwarded). It switches the TMessage from
 read mode to write mode and resets some internal pointers. Change also
 required change in way private TMessage ctor is called by friend
 TSocket::Recv() method.

git-svn-id: http://root.cern.ch/svn/root/trunk@516 27541ba8-7e3a-0410-8455-c3a389f83636
---
 net/inc/TMessage.h   |  5 +++--
 net/src/TMessage.cxx | 23 ++++++++++++-----------
 net/src/TSocket.cxx  | 10 +++++-----
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/net/inc/TMessage.h b/net/inc/TMessage.h
index 1d63d0bde22..df57794b0e9 100644
--- a/net/inc/TMessage.h
+++ b/net/inc/TMessage.h
@@ -1,4 +1,4 @@
-// @(#)root/net:$Name$:$Id$
+// @(#)root/net:$Name:  $:$Id: TMessage.h,v 1.1.1.1 2000/05/16 17:00:44 rdm Exp $
 // Author: Fons Rademakers   19/12/96
 
 /*************************************************************************
@@ -43,8 +43,9 @@ private:
 
 public:
    TMessage(UInt_t what = kMESS_ANY);
-   virtual ~TMessage();
+   virtual ~TMessage() { }
 
+   void     Forward();
    TClass  *GetClass() const { return fClass; }
    void     Reset();
    void     Reset(UInt_t what) { SetWhat(what); Reset(); }
diff --git a/net/src/TMessage.cxx b/net/src/TMessage.cxx
index 5a6c3789a56..ce413f05d25 100644
--- a/net/src/TMessage.cxx
+++ b/net/src/TMessage.cxx
@@ -1,4 +1,4 @@
-// @(#)root/net:$Name$:$Id$
+// @(#)root/net:$Name:  $:$Id: TMessage.cxx,v 1.1.1.1 2000/05/16 17:00:44 rdm Exp $
 // Author: Fons Rademakers   19/12/96
 
 /*************************************************************************
@@ -35,7 +35,7 @@ TMessage::TMessage(UInt_t what) : TBuffer(kWrite)
    // will wait for an acknowledgement from the remote side. This makes
    // the sending process synchronous.
 
-   // space at the beginning of the message to contain the message length
+   // space at the beginning of the message reserved for the message length
    UInt_t   reserved = 0;
    *this << reserved;
 
@@ -50,9 +50,8 @@ TMessage::TMessage(void *buf, Int_t bufsize) : TBuffer(kRead, bufsize, buf)
    // Create a TMessage object for reading objects. The objects will be
    // read from buf. Use the What() method to get the message type.
 
-   // pretend there is space at the beginning for the message length
-   // this word will never be accessed, only used for offset calculation
-   fBuffer -= sizeof(UInt_t);
+   // skip space at the beginning of the message reserved for the message length
+   fBufCur += sizeof(UInt_t);
 
    *this >> fWhat;
 
@@ -65,12 +64,15 @@ TMessage::TMessage(void *buf, Int_t bufsize) : TBuffer(kRead, bufsize, buf)
 }
 
 //______________________________________________________________________________
-TMessage::~TMessage()
+void TMessage::Forward()
 {
-   // TMessage dtor. In case we were reading reset fBuffer.
+   // Change a buffer that was received into one that can be send, i.e.
+   // forward a just received message.
 
-   if (IsReading())
-      fBuffer += sizeof(UInt_t);
+   if (IsReading()) {
+      SetWriteMode();
+      SetBufferOffset(fBufSize);
+   }
 }
 
 //______________________________________________________________________________
@@ -100,8 +102,7 @@ void TMessage::SetWhat(UInt_t what)
    // Using this method one can change the message type a posteriory.
 
    char *buf = Buffer();
-   if (IsWriting())
-      buf += sizeof(UInt_t);   // skip reserved space
+   buf += sizeof(UInt_t);   // skip reserved length space
    tobuf(buf, what);
    fWhat = what;
 }
diff --git a/net/src/TSocket.cxx b/net/src/TSocket.cxx
index a7a1575f1b1..aa4fc00e671 100644
--- a/net/src/TSocket.cxx
+++ b/net/src/TSocket.cxx
@@ -1,4 +1,4 @@
-// @(#)root/net:$Name:  $:$Id: TSocket.cxx,v 1.1.1.1 2000/05/16 17:00:44 rdm Exp $
+// @(#)root/net:$Name:  $:$Id: TSocket.cxx,v 1.2 2000/06/28 15:27:32 rdm Exp $
 // Author: Fons Rademakers   18/12/96
 
 /*************************************************************************
@@ -181,7 +181,7 @@ void TSocket::Close(Option_t *option)
    // shut down the connection. This will close the connection also
    // for the parent of this process. Also called via the dtor (without
    // option "force", call explicitely Close("force") if this is desired).
-   
+
    Bool_t force = option ? (!strcmp(option, "force") ? kTRUE : kFALSE) : kFALSE;
 
    if (fSocket != -1) {
@@ -394,8 +394,8 @@ Int_t TSocket::Recv(TMessage *&mess)
    }
    len = net2host(len);  //from network to host byte order
 
-   char *buf = new char[len];
-   if ((n = gSystem->RecvRaw(fSocket, buf, len, 0)) <= 0) {
+   char *buf = new char[len+sizeof(UInt_t)];
+   if ((n = gSystem->RecvRaw(fSocket, buf+sizeof(UInt_t), len, 0)) <= 0) {
       delete [] buf;
       mess = 0;
       return n;
@@ -404,7 +404,7 @@ Int_t TSocket::Recv(TMessage *&mess)
    fBytesRecv  += n + sizeof(UInt_t);
    fgBytesRecv += n + sizeof(UInt_t);
 
-   mess = new TMessage(buf, len);
+   mess = new TMessage(buf, len+sizeof(UInt_t));
 
    if (mess->What() & kMESS_ACK) {
       char ok[2] = { 'o', 'k' };
-- 
GitLab