ENH: UIPstream when reaches eof deletes the underlying buffer.

Only in PstreamBuffers mode. This makes sure that data from other processors
already handled gets deleted.
This commit is contained in:
mattijs
2010-03-04 15:03:10 +00:00
parent 18eb2d7099
commit e4b4bf2bf0
5 changed files with 40 additions and 1 deletions

View File

@ -38,7 +38,17 @@ Foam::IPstream::IPstream
) )
: :
Pstream(commsType, bufSize), Pstream(commsType, bufSize),
UIPstream(commsType, fromProcNo, buf_, externalBufPosition_), UIPstream
(
commsType,
fromProcNo,
buf_,
externalBufPosition_,
UPstream::msgType(), // tag
false, // do not clear buf_ if at end
format,
version
),
externalBufPosition_(0) externalBufPosition_(0)
{} {}

View File

@ -77,6 +77,21 @@ inline void Foam::UIPstream::readFromBuffer
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::UIPstream::~UIPstream()
{
if (clearAtEnd_ && eof())
{
if (debug)
{
Pout<< "UIPstream::~UIPstream() : clearing externalBuf_ of size "
<< externalBuf_.size() << endl;
}
externalBuf_.clearStorage();
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::Istream& Foam::UIPstream::read(token& t) Foam::Istream& Foam::UIPstream::read(token& t)

View File

@ -67,6 +67,8 @@ class UIPstream
const int tag_; const int tag_;
const bool clearAtEnd_;
label messageSize_; label messageSize_;
@ -96,6 +98,7 @@ public:
DynamicList<char>& externalBuf, DynamicList<char>& externalBuf,
label& externalBufPosition, label& externalBufPosition,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const bool clearAtEnd = false, // destroy externalBuf if at end
streamFormat format=BINARY, streamFormat format=BINARY,
versionNumber version=currentVersion versionNumber version=currentVersion
); );
@ -104,6 +107,11 @@ public:
UIPstream(const int fromProcNo, PstreamBuffers&); UIPstream(const int fromProcNo, PstreamBuffers&);
// Destructor
~UIPstream();
// Member functions // Member functions
// Inquiry // Inquiry

View File

@ -38,6 +38,7 @@ Foam::UIPstream::UIPstream
DynamicList<char>& externalBuf, DynamicList<char>& externalBuf,
label& externalBufPosition, label& externalBufPosition,
const int tag, const int tag,
const bool clearAtEnd,
streamFormat format, streamFormat format,
versionNumber version versionNumber version
) )
@ -48,6 +49,7 @@ Foam::UIPstream::UIPstream
externalBuf_(externalBuf), externalBuf_(externalBuf),
externalBufPosition_(externalBufPosition), externalBufPosition_(externalBufPosition),
tag_(tag), tag_(tag),
clearAtEnd_(clearAtEnd),
messageSize_(0) messageSize_(0)
{ {
notImplemented notImplemented
@ -59,6 +61,7 @@ Foam::UIPstream::UIPstream
"DynamicList<char>&," "DynamicList<char>&,"
"label&," "label&,"
"const int tag," "const int tag,"
"const bool,"
"streamFormat, versionNumber" "streamFormat, versionNumber"
")" ")"
); );

View File

@ -42,6 +42,7 @@ Foam::UIPstream::UIPstream
DynamicList<char>& externalBuf, DynamicList<char>& externalBuf,
label& externalBufPosition, label& externalBufPosition,
const int tag, const int tag,
const bool clearAtEnd,
streamFormat format, streamFormat format,
versionNumber version versionNumber version
) )
@ -52,6 +53,7 @@ Foam::UIPstream::UIPstream
externalBuf_(externalBuf), externalBuf_(externalBuf),
externalBufPosition_(externalBufPosition), externalBufPosition_(externalBufPosition),
tag_(tag), tag_(tag),
clearAtEnd_(clearAtEnd),
messageSize_(0) messageSize_(0)
{ {
setOpened(); setOpened();
@ -125,6 +127,7 @@ Foam::UIPstream::UIPstream(const int fromProcNo, PstreamBuffers& buffers)
externalBuf_(buffers.recvBuf_[fromProcNo]), externalBuf_(buffers.recvBuf_[fromProcNo]),
externalBufPosition_(buffers.recvBufPos_[fromProcNo]), externalBufPosition_(buffers.recvBufPos_[fromProcNo]),
tag_(buffers.tag_), tag_(buffers.tag_),
clearAtEnd_(true),
messageSize_(0) messageSize_(0)
{ {
if (commsType() != UPstream::scheduled && !buffers.finishedSendsCalled_) if (commsType() != UPstream::scheduled && !buffers.finishedSendsCalled_)