input/Proxy: use InputStreamPtr

This commit is contained in:
Max Kellermann
2017-12-26 11:37:29 +01:00
parent fb9a2c5431
commit 49619fbd77
9 changed files with 50 additions and 59 deletions

View File

@@ -438,21 +438,16 @@ CurlInputStream::DoSeek(offset_type new_offset)
inline InputStream *
CurlInputStream::Open(const char *url, Mutex &mutex, Cond &cond)
{
CurlInputStream *c = new CurlInputStream((*curl_init)->GetEventLoop(),
url, mutex, cond);
auto c = std::make_unique<CurlInputStream>((*curl_init)->GetEventLoop(),
url, mutex, cond);
try {
BlockingCall(c->GetEventLoop(), [c](){
c->InitEasy();
c->StartRequest();
});
} catch (...) {
delete c;
throw;
}
BlockingCall(c->GetEventLoop(), [&c](){
c->InitEasy();
c->StartRequest();
});
auto icy = c->icy;
return new IcyInputStream(c, std::move(icy));
return new IcyInputStream(std::move(c), std::move(icy));
}
static InputStream *

View File

@@ -47,9 +47,8 @@ class RewindInputStream final : public ProxyInputStream {
char buffer[64 * 1024];
public:
RewindInputStream(InputStream *_input)
:ProxyInputStream(_input) {
}
explicit RewindInputStream(InputStreamPtr _input)
:ProxyInputStream(std::move(_input)) {}
/* virtual methods from InputStream */
@@ -71,7 +70,7 @@ private:
* buffer contain more data for the next read operation?
*/
bool ReadingFromBuffer() const noexcept {
return tail > 0 && offset < input.GetOffset();
return tail > 0 && offset < input->GetOffset();
}
};
@@ -82,7 +81,7 @@ RewindInputStream::Read(void *ptr, size_t read_size)
/* buffered read */
assert(head == (size_t)offset);
assert(tail == (size_t)input.GetOffset());
assert(tail == (size_t)input->GetOffset());
if (read_size > tail - head)
read_size = tail - head;
@@ -95,9 +94,9 @@ RewindInputStream::Read(void *ptr, size_t read_size)
} else {
/* pass method call to underlying stream */
size_t nbytes = input.Read(ptr, read_size);
size_t nbytes = input->Read(ptr, read_size);
if (input.GetOffset() > (offset_type)sizeof(buffer))
if (input->GetOffset() > (offset_type)sizeof(buffer))
/* disable buffering */
tail = 0;
else if (tail == (size_t)offset) {
@@ -106,7 +105,7 @@ RewindInputStream::Read(void *ptr, size_t read_size)
memcpy(buffer + tail, ptr, nbytes);
tail += nbytes;
assert(tail == (size_t)input.GetOffset());
assert(tail == (size_t)input->GetOffset());
}
CopyAttributes();
@@ -125,7 +124,7 @@ RewindInputStream::Seek(offset_type new_offset)
assert(!ReadingFromBuffer() ||
head == (size_t)offset);
assert(tail == (size_t)input.GetOffset());
assert(tail == (size_t)input->GetOffset());
head = (size_t)new_offset;
offset = new_offset;
@@ -138,8 +137,8 @@ RewindInputStream::Seek(offset_type new_offset)
}
}
InputStream *
input_rewind_open(InputStream *is)
InputStreamPtr
input_rewind_open(InputStreamPtr is)
{
assert(is != nullptr);
assert(!is->IsReady() || is->GetOffset() == 0);
@@ -148,5 +147,5 @@ input_rewind_open(InputStream *is)
/* seekable resources don't need this plugin */
return is;
return new RewindInputStream(is);
return InputStreamPtr(new RewindInputStream(std::move(is)));
}

View File

@@ -28,10 +28,9 @@
#define MPD_INPUT_REWIND_HXX
#include "check.h"
#include "input/Ptr.hxx"
class InputStream;
InputStream *
input_rewind_open(InputStream *is);
InputStreamPtr
input_rewind_open(InputStreamPtr is);
#endif