OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

IPread.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Read token and binary block from IPstream
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "IPstream.H"
00031 #include "long.H"
00032 #include "PstreamGlobals.H"
00033 
00034 extern "C"
00035 {
00036 #   include <linux/gamma/libgamma.h>
00037 }
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 namespace Foam
00042 {
00043 
00044 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
00045 
00046 IPstream::IPstream
00047 (
00048     const commsTypes commsType,
00049     const int fromProcNo,
00050     const label bufSize,
00051     streamFormat format,
00052     versionNumber version
00053 )
00054 :
00055     Pstream(commsType, bufSize),
00056     Istream(format, version),
00057     fromProcNo_(fromProcNo),
00058     messageSize_(0)
00059 {
00060     // Blocking read.
00061 
00062     setOpened();
00063     setGood();
00064 
00065     if (Pstream::debug)
00066     {
00067         Pout<< "IPstream::IPstream : Starting receive from " << fromProcNo_
00068             << " recvIndex:" << PstreamGlobals::recvIndex[fromProcNo_]
00069             << Foam::endl;
00070     }
00071 
00072     PstreamGlobals::gammaWait(fromProcNo_);
00073 
00074     label ready = PstreamGlobals::consumeIndex[fromProcNo_];
00075     messageSize_ = PstreamGlobals::recvBufLen[ready][fromProcNo_];
00076 
00077     if (!bufSize)
00078     {
00079         if (Pstream::debug)
00080         {
00081             Pout<< "IPstream::IPstream : sizing buffer to " << messageSize_
00082                 << endl;
00083         }
00084 
00085         buf_.setSize(messageSize_);
00086     }
00087 
00088     PstreamGlobals::copyReceive(fromProcNo_, buf_.begin(), buf_.size());
00089 
00090     if (Pstream::debug)
00091     {
00092         Pout<< "IPstream::IPstream : Received " << messageSize_
00093             << " from " << fromProcNo_
00094             << Foam::endl;
00095     }
00096 }
00097 
00098 
00099 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00100 
00101 label IPstream::read
00102 (
00103     const commsTypes commsType,
00104     const int fromProcNo,
00105     char* buf,
00106     const std::streamsize bufSize
00107 )
00108 {
00109     // Blocking read.
00110     label messageSize;
00111 
00112     if (Pstream::debug)
00113     {
00114         Pout<< "IPstream::read : Starting receive from " << fromProcNo
00115             << " recvIndex:" << PstreamGlobals::recvIndex[fromProcNo]
00116             << Foam::endl;
00117     }
00118 
00119     PstreamGlobals::gammaWait(fromProcNo);
00120     messageSize = PstreamGlobals::copyReceive(fromProcNo, buf, bufSize);
00121 
00122     if (Pstream::debug)
00123     {
00124         Pout<< "IPstream::read : Received " << messageSize
00125             << " from " << fromProcNo
00126             << Foam::endl;
00127     }
00128 
00129     return messageSize;
00130 }
00131 
00132 
00133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00134 
00135 } // End namespace Foam
00136 
00137 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd