예제 #1
0
Foam::OFstream::OFstream
(
    const fileName& pathname,
    streamFormat format,
    versionNumber version,
    compressionType compression
)
    :
    OFstreamAllocator(pathname, compression),
    OSstream(*ofPtr_, "OFstream.sinkFile_", format, version, compression),
    pathname_(pathname)
{
    setClosed();
    setState(ofPtr_->rdstate());

    if (!good())
    {
        if (debug)
        {
            Info<< "IFstream::IFstream(const fileName&,"
                "streamFormat format=ASCII,"
                "versionNumber version=currentVersion) : "
                "could not open file for input\n"
                "in stream " << info() << Foam::endl;
        }

        setBad();
    }
    else
    {
        setOpened();
    }

    lineNumber_ = 1;
}
예제 #2
0
파일: BaseFile.cpp 프로젝트: spinos/aphid
bool BaseFile::create(const std::string & filename)
{
	if(!doCreate(filename)) return false;
	
	setFileName(filename);
	setOpened();
	return true;
}
예제 #3
0
bool CustomDataSet::open()
{
    if ( m_lsVar.isEmpty() ) {
        error()->setError(QString("No data in CustomDataSet datasource") );
        return false;
    }
    recno() =0;
    setOpened(true);
    return true;
}
bool LocalSocketPrivate_Unix::setSocketDescriptor(quintptr socketDescriptor)
{
	// Set to non blocking
// 	int	flags	=	fcntl(socketDescriptor, F_GETFL, 0);
// 	fcntl(socketDescriptor, F_SETFL, flags | O_NONBLOCK);
	
	// Don't emit SIGPIPE signal but return EPIPE on systems that support it
#ifdef SO_NOSIGPIPE
	int set = 1;
	setsockopt(socketDescriptor, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
#endif
	
	m_socketDescriptor	=	socketDescriptor;
	
	// Get read buffer size
	int				buff;
	socklen_t	optlen	=	sizeof(buff);
	int	tmp	=	getsockopt(m_socketDescriptor, SOL_SOCKET, SO_RCVBUF, &buff, &optlen);
	
	if(tmp > 0)
		m_readBufferSize	=	tmp - (sizeof(msghdr) + sizeof(iovec) + sizeof(cmsghdr));
	else
		m_readBufferSize	=	LocalSocketPrivate::readBufferSize();
  
#ifndef USE_SELECT
  // Init epoll()
  if(m_epollFd_rw <= 0) {
    m_epollFd_rw  = epoll_create1(0);
    m_epollFd_r   = epoll_create1(0);
    m_epollFd_w   = epoll_create1(0);
  }
  
  m_epollEvent_rw.events  = EPOLLIN | EPOLLOUT;
  m_epollEvent_r.events   = EPOLLIN;
  m_epollEvent_w.events   = EPOLLOUT;
  
  // Add watched fd
  if(epoll_ctl(m_epollFd_rw, EPOLL_CTL_ADD, m_socketDescriptor, &m_epollEvent_rw) != 0
    || epoll_ctl(m_epollFd_r, EPOLL_CTL_ADD, m_socketDescriptor, &m_epollEvent_r) != 0
    || epoll_ctl(m_epollFd_w, EPOLL_CTL_ADD, m_socketDescriptor, &m_epollEvent_w) != 0
  ) {
    close();
    setError(QStringLiteral("Cannot set socket descriptor: %1").arg(strerror(errno)));
    return false;
  }
  
#endif

	setOpened();
	
	return true;
}
예제 #5
0
Foam::UOPstream::UOPstream(const int toProcNo, PstreamBuffers& buffers)
:
    UPstream(buffers.commsType_),
    Ostream(buffers.format_, buffers.version_),
    toProcNo_(toProcNo),
    sendBuf_(buffers.sendBuf_[toProcNo]),
    tag_(buffers.tag_),
    comm_(buffers.comm_),
    sendAtDestruct_(buffers.commsType_ != UPstream::nonBlocking)
{
    setOpened();
    setGood();
}
예제 #6
0
파일: IPread.C 프로젝트: Brzous/WindFOAM
IPstream::IPstream
(
    const commsTypes commsType,
    const int fromProcNo,
    const label bufSize,
    streamFormat format,
    versionNumber version
)
:
    Pstream(commsType, bufSize),
    Istream(format, version),
    fromProcNo_(fromProcNo),
    messageSize_(0)
{
    // Blocking read.

    setOpened();
    setGood();

    if (Pstream::debug)
    {
        Pout<< "IPstream::IPstream : Starting receive from " << fromProcNo_
            << " recvIndex:" << PstreamGlobals::recvIndex[fromProcNo_]
            << Foam::endl;
    }

    PstreamGlobals::gammaWait(fromProcNo_);

    label ready = PstreamGlobals::consumeIndex[fromProcNo_];
    messageSize_ = PstreamGlobals::recvBufLen[ready][fromProcNo_];

    if (!bufSize)
    {
        if (Pstream::debug)
        {
            Pout<< "IPstream::IPstream : sizing buffer to " << messageSize_
                << endl;
        }

        buf_.setSize(messageSize_);
    }

    PstreamGlobals::copyReceive(fromProcNo_, buf_.begin(), buf_.size());

    if (Pstream::debug)
    {
        Pout<< "IPstream::IPstream : Received " << messageSize_
            << " from " << fromProcNo_
            << Foam::endl;
    }
}
예제 #7
0
파일: BaseFile.cpp 프로젝트: spinos/aphid
bool BaseFile::open(const std::string & fileName)
{
	if(!FileExists(fileName)) {
		setLatestError(BaseFile::FileNotFound);
		return false;
	}
	
	if(!clear()) return false;
	
	doClose();
	if(!doRead(fileName)) return false;
	afterOpen();
	setFileName(fileName);
	setOpened();
    
	return true;
}
예제 #8
0
파일: IFstream.C 프로젝트: Brzous/WindFOAM
Foam::IFstream::IFstream
(
    const fileName& pathname,
    streamFormat format,
    versionNumber version
)
:
    IFstreamAllocator(pathname),
    ISstream
    (
        *ifPtr_,
        "IFstream.sourceFile_",
        format,
        version,
        IFstreamAllocator::compression_
    ),
    pathname_(pathname)
{
    setClosed();

    setState(ifPtr_->rdstate());

    if (!good())
    {
        if (debug)
        {
            Info<< "IFstream::IFstream(const fileName&,"
                   "streamFormat=ASCII,"
                   "versionNumber=currentVersion) : "
                   "could not open file for input"
                << endl << info() << endl;
        }

        setBad();
    }
    else
    {
        setOpened();
    }

    lineNumber_ = 1;
}
예제 #9
0
파일: IPread.C 프로젝트: Brzous/WindFOAM
Foam::IPstream::IPstream
(
    const commsTypes commsType,
    const int fromProcNo,
    const label bufSize,
    streamFormat format,
    versionNumber version
)
:
    Pstream(commsType, bufSize),
    Istream(format, version),
    fromProcNo_(fromProcNo),
    messageSize_(0)
{
    setOpened();
    setGood();

    MPI_Status status;

    // If the buffer size is not specified, probe the incomming message
    // and set it
    if (!bufSize)
    {
        MPI_Probe(procID(fromProcNo_), msgType(), MPI_COMM_WORLD, &status);
        MPI_Get_count(&status, MPI_BYTE, &messageSize_);

        buf_.setSize(messageSize_);
    }

    messageSize_ = read(commsType, fromProcNo_, buf_.begin(), buf_.size());

    if (!messageSize_)
    {
        FatalErrorIn
        (
            "IPstream::IPstream(const int fromProcNo, "
            "const label bufSize, streamFormat format, versionNumber version)"
        )   << "read failed"
            << Foam::abort(FatalError);
    }
}
예제 #10
0
Foam::OPstream::OPstream
(
    const commsTypes commsType,
    const int toProcNo,
    const label bufSize,
    streamFormat format,
    versionNumber version
)
:
    Pstream(commsType, bufSize),
    Ostream(format, version),
    toProcNo_(toProcNo)
{
    setOpened();
    setGood();

    if (!bufSize)
    {
        buf_.setSize(1000);
    }
}
예제 #11
0
Foam::UOPstream::UOPstream
(
    const commsTypes commsType,
    const int toProcNo,
    DynamicList<char>& sendBuf,
    const int tag,
    const label comm,
    const bool sendAtDestruct,
    streamFormat format,
    versionNumber version
)
:
    UPstream(commsType),
    Ostream(format, version),
    toProcNo_(toProcNo),
    sendBuf_(sendBuf),
    tag_(tag),
    comm_(comm),
    sendAtDestruct_(sendAtDestruct)
{
    setOpened();
    setGood();
}
예제 #12
0
bool CustomDataSet::close()
{
    recno() =0;
    setOpened(false);
    return true;
}
예제 #13
0
Foam::UIPstream::UIPstream
(
    const commsTypes commsType,
    const int fromProcNo,
    DynamicList<char>& externalBuf,
    label& externalBufPosition,
    const int tag,
    const bool clearAtEnd,
    streamFormat format,
    versionNumber version
)
:
    UPstream(commsType),
    Istream(format, version),
    fromProcNo_(fromProcNo),
    externalBuf_(externalBuf),
    externalBufPosition_(externalBufPosition),
    tag_(tag),
    clearAtEnd_(clearAtEnd),
    messageSize_(0)
{
    setOpened();
    setGood();

    if (commsType == UPstream::nonBlocking)
    {
        // Message is already received into externalBuf
    }
    else
    {
        MPI_Status status;

        label wantedSize = externalBuf_.capacity();

        if (debug)
        {
            Pout<< "UIPstream::UIPstream : read from:" << fromProcNo
                << " tag:" << tag << " wanted size:" << wantedSize
                << Foam::endl;
        }


        // If the buffer size is not specified, probe the incomming message
        // and set it
        if (!wantedSize)
        {
            MPI_Probe(procID(fromProcNo_), tag_, MPI_COMM_WORLD, &status);
            MPI_Get_count(&status, MPI_BYTE, &messageSize_);

            externalBuf_.setCapacity(messageSize_);
            wantedSize = messageSize_;

            if (debug)
            {
                Pout<< "UIPstream::UIPstream : probed size:" << wantedSize
                    << Foam::endl;
            }
        }

        messageSize_ = UIPstream::read
        (
            commsType,
            fromProcNo_,
            externalBuf_.begin(),
            wantedSize,
            tag_
        );

        // Set addressed size. Leave actual allocated memory intact.
        externalBuf_.setSize(messageSize_);

        if (!messageSize_)
        {
            FatalErrorIn
            (
                "UIPstream::UIPstream(const commsTypes, const int, "
                "DynamicList<char>&, streamFormat, versionNumber)"
            )   << "read failed"
                << Foam::abort(FatalError);
        }
    }
}
예제 #14
0
Foam::UIPstream::UIPstream(const int fromProcNo, PstreamBuffers& buffers)
:
    UPstream(buffers.commsType_),
    Istream(buffers.format_, buffers.version_),
    fromProcNo_(fromProcNo),
    externalBuf_(buffers.recvBuf_[fromProcNo]),
    externalBufPosition_(buffers.recvBufPos_[fromProcNo]),
    tag_(buffers.tag_),
    clearAtEnd_(true),
    messageSize_(0)
{
    if (commsType() != UPstream::scheduled && !buffers.finishedSendsCalled_)
    {
        FatalErrorIn("UIPstream::UIPstream(const int, PstreamBuffers&)")
            << "PstreamBuffers::finishedSends() never called." << endl
            << "Please call PstreamBuffers::finishedSends() after doing"
            << " all your sends (using UOPstream) and before doing any"
            << " receives (using UIPstream)" << Foam::exit(FatalError);
    }

    setOpened();
    setGood();

    if (commsType() == UPstream::nonBlocking)
    {
        // Message is already received into externalBuf
        messageSize_ = buffers.recvBuf_[fromProcNo].size();
    }
    else
    {
        MPI_Status status;

        label wantedSize = externalBuf_.capacity();

        if (debug)
        {
            Pout<< "UIPstream::UIPstream PstreamBuffers :"
                << " read from:" << fromProcNo
                << " tag:" << tag_ << " wanted size:" << wantedSize
                << Foam::endl;
        }

        // If the buffer size is not specified, probe the incomming message
        // and set it
        if (!wantedSize)
        {
            MPI_Probe(procID(fromProcNo_), tag_, MPI_COMM_WORLD, &status);
            MPI_Get_count(&status, MPI_BYTE, &messageSize_);

            externalBuf_.setCapacity(messageSize_);
            wantedSize = messageSize_;

            if (debug)
            {
                Pout<< "UIPstream::UIPstream PstreamBuffers : probed size:"
                    << wantedSize << Foam::endl;
            }
        }

        messageSize_ = UIPstream::read
        (
            commsType(),
            fromProcNo_,
            externalBuf_.begin(),
            wantedSize,
            tag_
        );

        // Set addressed size. Leave actual allocated memory intact.
        externalBuf_.setSize(messageSize_);

        if (!messageSize_)
        {
            FatalErrorIn
            (
                "UIPstream::UIPstream(const int, PstreamBuffers&)"
            )   << "read failed"
                << Foam::abort(FatalError);
        }
    }
}
예제 #15
0
bool TestVarint::close()
{
    recno() =0;
    setOpened(false);
    return true;
}
IPstream::IPstream
(
    const int fromProcNo,
    const label bufSize,
    streamFormat format,
    versionNumber version
)
:
    Pstream(bufSize),
    Istream(format, version),
    fromProcNo_(fromProcNo),
    messageSize_(0)
{
    setOpened();
    setGood();

    int bufid, tag, tid;

    // If the buffer size is not specified then probe the incomming message

    if (!bufSize)
    {
        // Probe read buffer until message arrives.
        while (!(bufid = pvm_probe(procID(fromProcNo_), msgType())));

        // When the message arrives find its size
        pvm_bufinfo(bufid, &messageSize_, &tag, &tid);

        // Resize buffer to message size
        buf_.setSize(messageSize_);
    }


    // Read message into buffer

    if
    (
        pvm_precv
        (
            procID(fromProcNo_),
            msgType(),
            buf_.begin(),
            buf_.size(),
            PVM_BYTE,
            &tid, &tag, &messageSize_
        ) != PvmOk
    )
    {
        FatalErrorIn("IPstream::IPstream(const int fromProcNo)")
            << "pvm_precv cannot receive incomming message"
            << ::abort;
    }


    // Check size of message read

    if (messageSize_ > buf_.size())
    {
        FatalErrorIn("IPstream::IPstream(const int fromProcNo)")
            << "buffer (" << buf_.size()
            << ") not large enough for incomming message ("
            << messageSize_ << ')'
            << ::abort;
    }
}