Line 1... |
Line 1... |
// $Id: RlinkPortFifo.cpp 466 2012-12-30 13:26:55Z mueller $
|
// $Id: RlinkPortFifo.cpp 492 2013-02-24 22:14:47Z mueller $
|
//
|
//
|
// Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2011-2013 y Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
// Software Foundation, either version 2, or at your option any later version.
|
// Software Foundation, either version 2, or at your option any later version.
|
//
|
//
|
Line 11... |
Line 11... |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for complete details.
|
// for complete details.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
// Date Rev Version Comment
|
// Date Rev Version Comment
|
|
// 2013-02-23 492 1.1 use RparseUrl
|
// 2011-03-27 374 1.0 Initial version
|
// 2011-03-27 374 1.0 Initial version
|
// 2011-01-15 356 0.1 First draft
|
// 2011-01-15 356 0.1 First draft
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: RlinkPortFifo.cpp 466 2012-12-30 13:26:55Z mueller $
|
\version $Id: RlinkPortFifo.cpp 492 2013-02-24 22:14:47Z mueller $
|
\brief Implemenation of RlinkPortFifo.
|
\brief Implemenation of RlinkPortFifo.
|
*/
|
*/
|
|
|
#include <sys/types.h>
|
#include <sys/types.h>
|
#include <sys/stat.h>
|
#include <sys/stat.h>
|
Line 29... |
Line 30... |
#include <errno.h>
|
#include <errno.h>
|
|
|
#include "RlinkPortFifo.hpp"
|
#include "RlinkPortFifo.hpp"
|
|
|
using namespace std;
|
using namespace std;
|
using namespace Retro;
|
|
|
|
/*!
|
/*!
|
\class Retro::RlinkPortFifo
|
\class Retro::RlinkPortFifo
|
\brief FIXME_text
|
\brief FIXME_docs
|
*/
|
*/
|
|
|
|
// all method definitions in namespace Retro
|
|
namespace Retro {
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! Default constructor
|
//! Default constructor
|
|
|
RlinkPortFifo::RlinkPortFifo()
|
RlinkPortFifo::RlinkPortFifo()
|
: RlinkPort()
|
: RlinkPort()
|
Line 53... |
Line 56... |
// no need to call Close() here, no RlinkPortFifo::Close()
|
// no need to call Close() here, no RlinkPortFifo::Close()
|
// cleanup will be done by ~RlinkPort()
|
// cleanup will be done by ~RlinkPort()
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_text
|
//! FIXME_docs
|
|
|
bool RlinkPortFifo::Open(const std::string& url, RerrMsg& emsg)
|
bool RlinkPortFifo::Open(const std::string& url, RerrMsg& emsg)
|
{
|
{
|
if (IsOpen()) Close();
|
if (IsOpen()) Close();
|
|
|
if (!ParseUrl(url, "|keep|", emsg)) return false;
|
if (!fUrl.Set(url, "|keep|", emsg)) return false;
|
|
|
// Note: _rx fifo must be opened before the _tx fifo, otherwise the test
|
// Note: _rx fifo must be opened before the _tx fifo, otherwise the test
|
// bench might close with EOF on read prematurely (is a race condition).
|
// bench might close with EOF on read prematurely (is a race condition).
|
|
|
fFdWrite = OpenFifo(UrlPath() + "_rx", true, emsg);
|
fFdWrite = OpenFifo(fUrl.Path() + "_rx", true, emsg);
|
if (fFdWrite < 0) return false;
|
if (fFdWrite < 0) return false;
|
|
|
fFdRead = OpenFifo(UrlPath() + "_tx", false, emsg);
|
fFdRead = OpenFifo(fUrl.Path() + "_tx", false, emsg);
|
if (fFdRead < 0) {
|
if (fFdRead < 0) {
|
close(fFdWrite);
|
close(fFdWrite);
|
fFdWrite = -1;
|
fFdWrite = -1;
|
return false;
|
return false;
|
}
|
}
|
Line 80... |
Line 83... |
|
|
return true;
|
return true;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_text
|
//! FIXME_docs
|
|
|
int RlinkPortFifo::OpenFifo(const std::string& name, bool snd, RerrMsg& emsg)
|
int RlinkPortFifo::OpenFifo(const std::string& name, bool snd, RerrMsg& emsg)
|
{
|
{
|
struct stat stat_fifo;
|
struct stat stat_fifo;
|
|
|
Line 92... |
Line 95... |
|
|
irc = stat(name.c_str(), &stat_fifo);
|
irc = stat(name.c_str(), &stat_fifo);
|
if (irc == 0) {
|
if (irc == 0) {
|
if ((stat_fifo.st_mode & S_IFIFO) == 0) {
|
if ((stat_fifo.st_mode & S_IFIFO) == 0) {
|
emsg.Init("RlinkPortFifo::OpenFiFo()",
|
emsg.Init("RlinkPortFifo::OpenFiFo()",
|
string("\"") + name + string("\" exists but is not a pipe"));
|
string("'") + name + string("' exists but is not a pipe"));
|
return -1;
|
return -1;
|
}
|
}
|
} else {
|
} else {
|
mode_t mode = S_IRUSR | S_IWUSR; // user read and write allowed
|
mode_t mode = S_IRUSR | S_IWUSR; // user read and write allowed
|
irc = mkfifo(name.c_str(), mode);
|
irc = mkfifo(name.c_str(), mode);
|
if (irc != 0) {
|
if (irc != 0) {
|
emsg.InitErrno("RlinkPortFifo::OpenFifo()",
|
emsg.InitErrno("RlinkPortFifo::OpenFifo()",
|
string("mkfifo() for \"") + name + string("\" failed: "),
|
string("mkfifo() for '") + name + string("' failed: "),
|
errno);
|
errno);
|
return -1;
|
return -1;
|
}
|
}
|
}
|
}
|
|
|
irc = open(name.c_str(), snd ? O_WRONLY : O_RDONLY);
|
irc = open(name.c_str(), snd ? O_WRONLY : O_RDONLY);
|
if (irc < 0) {
|
if (irc < 0) {
|
emsg.InitErrno("RlinkPortFifo::OpenFifo()",
|
emsg.InitErrno("RlinkPortFifo::OpenFifo()",
|
string("open() for \"") + name + string("\" failed: "),
|
string("open() for '") + name + string("' failed: "),
|
errno);
|
errno);
|
return -1;
|
return -1;
|
}
|
}
|
|
|
return irc;
|
return irc;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
} // end namespace Retro
|
#if (defined(Retro_NoInline) || defined(Retro_RlinkPortFifo_NoInline))
|
|
#define inline
|
|
//#include "RlinkPortFifo.ipp"
|
|
#undef inline
|
|
#endif
|
|
|
|
No newline at end of file
|
No newline at end of file
|