poco/Redis/include/Poco/Redis/RedisStream.h
2015-11-03 22:36:46 +01:00

106 lines
2.0 KiB
C++

//
// RedisStream.h
//
// $Id$
//
// Library: Redis
// Package: Redis
// Module: RedisStream
//
// Definition of the RedisStream class.
//
// Copyright (c) 2012, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#ifndef Redis_RedisStream_INCLUDED
#define Redis_RedisStream_INCLUDED
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Net/StreamSocket.h"
#include <istream>
#include <ostream>
namespace Poco {
namespace Redis {
class RedisStreamBuf : public BufferedStreamBuf
{
public:
RedisStreamBuf(Net::StreamSocket& redis);
~RedisStreamBuf();
std::string readLine();
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
private:
enum
{
STREAM_BUFFER_SIZE = 1024
};
Net::StreamSocket& _redis;
};
class RedisIOS: public virtual std::ios
{
public:
RedisIOS(Net::StreamSocket& redis);
/// Creates the RedisIOS with the given socket.
~RedisIOS();
/// Destroys the RedisIOS.
///
/// Flushes the buffer, but does not close the socket.
RedisStreamBuf* rdbuf();
/// Returns a pointer to the internal RedisStreamBuf.
void close();
/// Flushes the stream.
protected:
RedisStreamBuf _buf;
};
class RedisOutputStream: public RedisIOS, public std::ostream
/// An output stream for writing to a Redis server.
{
public:
RedisOutputStream(Net::StreamSocket& redis);
/// Creates the RedisOutputStream with the given socket.
~RedisOutputStream();
/// Destroys the RedisOutputStream.
///
/// Flushes the buffer.
};
class RedisInputStream: public RedisIOS, public std::istream
/// An input stream for reading from a Redis server.
{
public:
RedisInputStream(Net::StreamSocket& redis);
/// Creates the RedisInputStream with the given socket.
~RedisInputStream();
/// Destroys the RedisInputStream.
std::string getline();
/// Redis uses /r/n as delimiter. This getline version removes
/// the /r from the result.
};
}} // Poco::Redis
#endif // Redis_RedisStream_INCLUDED