1//
2// RedisStream.cpp
3//
4// Library: Redis
5// Package: Redis
6// Module: RedisStream
7//
8// Implementation of the RedisStream class.
9//
10// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#include "Poco/Redis/RedisStream.h"
18#include <iostream>
19
20
21namespace Poco {
22namespace Redis {
23
24
25//
26// RedisStreamBuf
27//
28
29
30RedisStreamBuf::RedisStreamBuf(Net::StreamSocket& redis):
31 BufferedStreamBuf(STREAM_BUFFER_SIZE, std::ios::in | std::ios::out),
32 _redis(redis)
33{
34}
35
36
37RedisStreamBuf::~RedisStreamBuf()
38{
39}
40
41
42int RedisStreamBuf::readFromDevice(char* buffer, std::streamsize len)
43{
44 return _redis.receiveBytes(buffer, static_cast<int>(len));
45}
46
47
48int RedisStreamBuf::writeToDevice(const char* buffer, std::streamsize length)
49{
50 return _redis.sendBytes(buffer, static_cast<int>(length));
51}
52
53
54//
55// RedisIOS
56//
57
58
59RedisIOS::RedisIOS(Net::StreamSocket& redis):
60 _buf(redis)
61{
62 poco_ios_init(&_buf);
63}
64
65
66RedisIOS::~RedisIOS()
67{
68 try
69 {
70 _buf.sync();
71 }
72 catch (...)
73 {
74 }
75}
76
77
78RedisStreamBuf* RedisIOS::rdbuf()
79{
80 return &_buf;
81}
82
83
84void RedisIOS::close()
85{
86 _buf.sync();
87}
88
89
90//
91// RedisOutputStream
92//
93
94
95RedisOutputStream::RedisOutputStream(Net::StreamSocket& redis):
96 RedisIOS(redis),
97 std::ostream(&_buf)
98{
99}
100
101
102RedisOutputStream::~RedisOutputStream()
103{
104}
105
106
107RedisInputStream::RedisInputStream(Net::StreamSocket& redis):
108 RedisIOS(redis),
109 std::istream(&_buf)
110{
111}
112
113
114//
115// RedisInputStream
116//
117
118
119RedisInputStream::~RedisInputStream()
120{
121}
122
123
124std::string RedisInputStream::getline()
125{
126 std::string line;
127 std::getline(*this, line);
128 if ( line.size() > 0 ) line.erase(line.end() - 1);
129 return line;
130}
131
132
133} } // namespace Poco::Redis
134