Skip to content
Snippets Groups Projects
Commit 5ed9f464 authored by Fons Rademakers's avatar Fons Rademakers
Browse files

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
parent 78a10c15
No related merge requests found
// @(#)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(); }
......
// @(#)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;
}
// @(#)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' };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment