added creation mode "read" or "create" for pipe stream

This commit is contained in:
badaix 2016-05-05 11:58:52 +02:00
parent 28133c9091
commit 86b34af0c6

View file

@ -37,8 +37,19 @@ using namespace std;
PipeStream::PipeStream(PcmListener* pcmListener, const StreamUri& uri) : PcmStream(pcmListener, uri), fd_(-1) PipeStream::PipeStream(PcmListener* pcmListener, const StreamUri& uri) : PcmStream(pcmListener, uri), fd_(-1)
{ {
umask(0); umask(0);
if ((mkfifo(uri_.path.c_str(), 0666) != 0) && (errno != EEXIST)) string mode = uri_.query["mode"];
throw SnapException("failed to make fifo \"" + uri_.path + "\": " + cpt::to_string(errno)); if (mode.empty())
mode = "create";
logO << "PipeStream mode: " << mode << "\n";
if ((mode != "read") && (mode != "create"))
throw SnapException("create mode for fifo must be \"read\" or \"create\"");
if (mode == "create")
{
if ((mkfifo(uri_.path.c_str(), 0666) != 0) && (errno != EEXIST))
throw SnapException("failed to make fifo \"" + uri_.path + "\": " + cpt::to_string(errno));
}
} }