mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 16:57:16 +01:00
4a6bfc086c
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
128 lines
1.4 KiB
C++
128 lines
1.4 KiB
C++
//
|
|
// PipeStream.cpp
|
|
//
|
|
// Library: Foundation
|
|
// Package: Processes
|
|
// Module: PipeStream
|
|
//
|
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#include "Poco/PipeStream.h"
|
|
|
|
|
|
namespace Poco {
|
|
|
|
|
|
//
|
|
// PipeStreamBuf
|
|
//
|
|
|
|
|
|
PipeStreamBuf::PipeStreamBuf(const Pipe& pipe, openmode mode):
|
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, mode),
|
|
_pipe(pipe)
|
|
{
|
|
}
|
|
|
|
|
|
PipeStreamBuf::~PipeStreamBuf()
|
|
{
|
|
}
|
|
|
|
|
|
int PipeStreamBuf::readFromDevice(char* buffer, std::streamsize length)
|
|
{
|
|
return _pipe.readBytes(buffer, (int) length);
|
|
}
|
|
|
|
|
|
int PipeStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
|
{
|
|
return _pipe.writeBytes(buffer, (int) length);
|
|
}
|
|
|
|
|
|
void PipeStreamBuf::close()
|
|
{
|
|
_pipe.close(Pipe::CLOSE_BOTH);
|
|
}
|
|
|
|
|
|
//
|
|
// PipeIOS
|
|
//
|
|
|
|
|
|
PipeIOS::PipeIOS(const Pipe& pipe, openmode mode):
|
|
_buf(pipe, mode)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
PipeIOS::~PipeIOS()
|
|
{
|
|
try
|
|
{
|
|
_buf.sync();
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
PipeStreamBuf* PipeIOS::rdbuf()
|
|
{
|
|
return &_buf;
|
|
}
|
|
|
|
|
|
void PipeIOS::close()
|
|
{
|
|
_buf.sync();
|
|
_buf.close();
|
|
}
|
|
|
|
|
|
//
|
|
// PipeOutputStream
|
|
//
|
|
|
|
|
|
PipeOutputStream::PipeOutputStream(const Pipe& pipe):
|
|
PipeIOS(pipe, std::ios::out),
|
|
std::ostream(&_buf)
|
|
{
|
|
}
|
|
|
|
|
|
PipeOutputStream::~PipeOutputStream()
|
|
{
|
|
}
|
|
|
|
|
|
//
|
|
// PipeInputStream
|
|
//
|
|
|
|
|
|
PipeInputStream::PipeInputStream(const Pipe& pipe):
|
|
PipeIOS(pipe, std::ios::in),
|
|
std::istream(&_buf)
|
|
{
|
|
}
|
|
|
|
|
|
PipeInputStream::~PipeInputStream()
|
|
{
|
|
}
|
|
|
|
|
|
} // namespace Poco
|