1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00
SqMod/vendor/POCO/ApacheConnector/include/ApacheStream.h
Sandu Liviu Catalin 4a6bfc086c Major plugin refactor and cleanup.
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.
2021-01-30 08:51:39 +02:00

104 lines
2.4 KiB
C++

//
// ApacheStream.h
//
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef ApacheConnector_ApacheStream_INCLUDED
#define ApacheConnector_ApacheStream_INCLUDED
#include "ApacheConnector.h"
#include "Poco/BufferedStreamBuf.h"
#include <istream>
#include <ostream>
class ApacheStreamBuf: public Poco::BufferedStreamBuf
/// This is the streambuf class used for reading from and writing to a socket.
{
public:
ApacheStreamBuf(ApacheRequestRec* pApacheRequest, bool haveData = false);
/// Creates a ApacheStreamBuf with the given socket.
~ApacheStreamBuf();
/// Destroys the SocketStreamBuf.
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
ApacheRequestRec* _pApacheRequest;
bool _haveData;
};
class ApacheIOS: public virtual std::ios
/// The base class for ApacheStream, ApacheInputStream and
/// ApacheOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
ApacheIOS(ApacheRequestRec* pApacheRequest, bool haveData = false);
/// Creates the ApacheIOS with the given socket.
~ApacheIOS();
/// Destroys the ApacheIOS.
///
/// Flushes the buffer, but does not close the socket.
ApacheStreamBuf* rdbuf();
/// Returns a pointer to the internal ApacheStreamBuf.
void close();
/// Flushes the stream.
protected:
ApacheStreamBuf _buf;
};
class ApacheOutputStream: public ApacheIOS, public std::ostream
/// An output stream for writing to an Apache response.
{
public:
ApacheOutputStream(ApacheRequestRec* pApacheRequest);
/// Creates the ApacheOutputStream with the given socket.
~ApacheOutputStream();
/// Destroys the ApacheOutputStream.
///
/// Flushes the buffer.
};
class ApacheInputStream: public ApacheIOS, public std::istream
/// An input stream for reading from an Apache request.
///
/// Using formatted input from a ApacheInputStream
/// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads.
{
public:
ApacheInputStream(ApacheRequestRec* pApacheRequest);
/// Creates the ApacheInputStream with the given socket.
~ApacheInputStream();
/// Destroys the ApacheInputStream.
};
#endif // ApacheConnector_ApacheStream_INCLUDED