mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 12:07:13 +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.
134 lines
1.6 KiB
C++
134 lines
1.6 KiB
C++
//
|
|
// RedisStream.cpp
|
|
//
|
|
// Library: Redis
|
|
// Package: Redis
|
|
// Module: RedisStream
|
|
//
|
|
// Implementation of the RedisStream class.
|
|
//
|
|
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#include "Poco/Redis/RedisStream.h"
|
|
#include <iostream>
|
|
|
|
|
|
namespace Poco {
|
|
namespace Redis {
|
|
|
|
|
|
//
|
|
// RedisStreamBuf
|
|
//
|
|
|
|
|
|
RedisStreamBuf::RedisStreamBuf(Net::StreamSocket& redis):
|
|
BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out),
|
|
_redis(redis)
|
|
{
|
|
}
|
|
|
|
|
|
RedisStreamBuf::~RedisStreamBuf()
|
|
{
|
|
}
|
|
|
|
|
|
int RedisStreamBuf::readFromDevice(char* buffer, std::streamsize len)
|
|
{
|
|
return _redis.receiveBytes(buffer, len);
|
|
}
|
|
|
|
|
|
int RedisStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
|
|
{
|
|
return _redis.sendBytes(buffer, length);
|
|
}
|
|
|
|
|
|
//
|
|
// RedisIOS
|
|
//
|
|
|
|
|
|
RedisIOS::RedisIOS(Net::StreamSocket& redis):
|
|
_buf(redis)
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
|
|
RedisIOS::~RedisIOS()
|
|
{
|
|
try
|
|
{
|
|
_buf.sync();
|
|
}
|
|
catch (...)
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
RedisStreamBuf* RedisIOS::rdbuf()
|
|
{
|
|
return &_buf;
|
|
}
|
|
|
|
|
|
void RedisIOS::close()
|
|
{
|
|
_buf.sync();
|
|
}
|
|
|
|
|
|
//
|
|
// RedisOutputStream
|
|
//
|
|
|
|
|
|
RedisOutputStream::RedisOutputStream(Net::StreamSocket& redis):
|
|
RedisIOS(redis),
|
|
std::ostream(&_buf)
|
|
{
|
|
}
|
|
|
|
|
|
RedisOutputStream::~RedisOutputStream()
|
|
{
|
|
}
|
|
|
|
|
|
RedisInputStream::RedisInputStream(Net::StreamSocket& redis):
|
|
RedisIOS(redis),
|
|
std::istream(&_buf)
|
|
{
|
|
}
|
|
|
|
|
|
//
|
|
// RedisInputStream
|
|
//
|
|
|
|
|
|
RedisInputStream::~RedisInputStream()
|
|
{
|
|
}
|
|
|
|
|
|
std::string RedisInputStream::getline()
|
|
{
|
|
std::string line;
|
|
std::getline(*this, line);
|
|
if ( line.size() > 0 ) line.erase(line.end() - 1);
|
|
return line;
|
|
}
|
|
|
|
|
|
} } // namespace Poco::Redis
|