mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Delete method StreamInterface::GetSize
Followup to https://webrtc-review.googlesource.com/c/4821 Bug: webrtc:6424, webrtc:7811 Change-Id: I6a4d8b52937256832509ebd33123c7b004263d8f Reviewed-on: https://webrtc-review.googlesource.com/c/101181 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26199}
This commit is contained in:
parent
b344640771
commit
0a7d56e0e5
8 changed files with 8 additions and 54 deletions
|
@ -243,12 +243,6 @@ bool FileRotatingStream::Flush() {
|
||||||
return file_stream_->Flush();
|
return file_stream_->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileRotatingStream::GetSize(size_t* size) const {
|
|
||||||
// Not possible to get accurate size on disk when writing because of
|
|
||||||
// potential buffering.
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileRotatingStream::Close() {
|
void FileRotatingStream::Close() {
|
||||||
CloseCurrentFile();
|
CloseCurrentFile();
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,6 @@ class FileRotatingStream : public StreamInterface {
|
||||||
size_t* written,
|
size_t* written,
|
||||||
int* error) override;
|
int* error) override;
|
||||||
bool Flush() override;
|
bool Flush() override;
|
||||||
// Returns the total file size currently used on disk.
|
|
||||||
bool GetSize(size_t* size) const override;
|
|
||||||
void Close() override;
|
void Close() override;
|
||||||
|
|
||||||
// Opens the appropriate file(s). Call this before using the stream.
|
// Opens the appropriate file(s). Call this before using the stream.
|
||||||
|
|
|
@ -91,18 +91,15 @@ class MAYBE_FileRotatingStreamTest : public ::testing::Test {
|
||||||
void VerifyFileContents(const char* expected_contents,
|
void VerifyFileContents(const char* expected_contents,
|
||||||
const size_t expected_length,
|
const size_t expected_length,
|
||||||
const std::string& file_path) {
|
const std::string& file_path) {
|
||||||
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length]);
|
std::unique_ptr<uint8_t[]> buffer(new uint8_t[expected_length + 1]);
|
||||||
FileStream stream;
|
FileStream stream;
|
||||||
ASSERT_TRUE(stream.Open(file_path, "r", nullptr));
|
ASSERT_TRUE(stream.Open(file_path, "r", nullptr));
|
||||||
size_t size_read = 0;
|
size_t size_read = 0;
|
||||||
EXPECT_EQ(rtc::SR_SUCCESS, stream.ReadAll(buffer.get(), expected_length,
|
EXPECT_EQ(rtc::SR_EOS, stream.ReadAll(buffer.get(), expected_length + 1,
|
||||||
&size_read, nullptr));
|
&size_read, nullptr));
|
||||||
EXPECT_EQ(size_read, expected_length);
|
EXPECT_EQ(size_read, expected_length);
|
||||||
EXPECT_EQ(0, memcmp(expected_contents, buffer.get(),
|
EXPECT_EQ(0, memcmp(expected_contents, buffer.get(),
|
||||||
std::min(expected_length, size_read)));
|
std::min(expected_length, size_read)));
|
||||||
size_t file_size = 0;
|
|
||||||
EXPECT_TRUE(stream.GetSize(&file_size));
|
|
||||||
EXPECT_EQ(file_size, expected_length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<FileRotatingStream> stream_;
|
std::unique_ptr<FileRotatingStream> stream_;
|
||||||
|
@ -134,9 +131,10 @@ TEST_F(MAYBE_FileRotatingStreamTest, EmptyWrite) {
|
||||||
std::string logfile_path = stream_->GetFilePath(0);
|
std::string logfile_path = stream_->GetFilePath(0);
|
||||||
FileStream stream;
|
FileStream stream;
|
||||||
ASSERT_TRUE(stream.Open(logfile_path, "r", nullptr));
|
ASSERT_TRUE(stream.Open(logfile_path, "r", nullptr));
|
||||||
size_t file_size = 0;
|
char buf[1];
|
||||||
EXPECT_TRUE(stream.GetSize(&file_size));
|
size_t read_nbytes;
|
||||||
EXPECT_EQ(0u, file_size);
|
int read_error;
|
||||||
|
EXPECT_EQ(SR_EOS, stream.Read(buf, sizeof(buf), &read_nbytes, &read_error));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that a write operation followed by a read returns the expected data
|
// Tests that a write operation followed by a read returns the expected data
|
||||||
|
|
|
@ -42,7 +42,6 @@ class StringStream : public StreamInterface {
|
||||||
void Close() override;
|
void Close() override;
|
||||||
bool SetPosition(size_t position) override;
|
bool SetPosition(size_t position) override;
|
||||||
bool GetPosition(size_t* position) const override;
|
bool GetPosition(size_t* position) const override;
|
||||||
bool GetSize(size_t* size) const override;
|
|
||||||
bool ReserveSize(size_t size) override;
|
bool ReserveSize(size_t size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -107,12 +106,6 @@ bool StringStream::GetPosition(size_t* position) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StringStream::GetSize(size_t* size) const {
|
|
||||||
if (size)
|
|
||||||
*size = str_.size();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StringStream::ReserveSize(size_t size) {
|
bool StringStream::ReserveSize(size_t size) {
|
||||||
if (read_only_)
|
if (read_only_)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -38,7 +38,7 @@ class MemoryStream final : public StreamInterface {
|
||||||
void Close() override;
|
void Close() override;
|
||||||
bool SetPosition(size_t position) override;
|
bool SetPosition(size_t position) override;
|
||||||
bool GetPosition(size_t* position) const override;
|
bool GetPosition(size_t* position) const override;
|
||||||
bool GetSize(size_t* size) const override;
|
bool GetSize(size_t* size) const;
|
||||||
bool ReserveSize(size_t size) override;
|
bool ReserveSize(size_t size) override;
|
||||||
|
|
||||||
char* GetBuffer() { return buffer_; }
|
char* GetBuffer() { return buffer_; }
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
*/
|
*/
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -86,10 +85,6 @@ bool StreamInterface::GetPosition(size_t* position) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamInterface::GetSize(size_t* size) const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StreamInterface::Flush() {
|
bool StreamInterface::Flush() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -146,10 +141,6 @@ bool StreamAdapterInterface::GetPosition(size_t* position) const {
|
||||||
return stream_->GetPosition(position);
|
return stream_->GetPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamAdapterInterface::GetSize(size_t* size) const {
|
|
||||||
return stream_->GetSize(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool StreamAdapterInterface::ReserveSize(size_t size) {
|
bool StreamAdapterInterface::ReserveSize(size_t size) {
|
||||||
return stream_->ReserveSize(size);
|
return stream_->ReserveSize(size);
|
||||||
}
|
}
|
||||||
|
@ -317,18 +308,6 @@ bool FileStream::GetPosition(size_t* position) const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileStream::GetSize(size_t* size) const {
|
|
||||||
RTC_DCHECK(nullptr != size);
|
|
||||||
if (!file_)
|
|
||||||
return false;
|
|
||||||
struct stat file_stats;
|
|
||||||
if (fstat(fileno(file_), &file_stats) != 0)
|
|
||||||
return false;
|
|
||||||
if (size)
|
|
||||||
*size = file_stats.st_size;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileStream::ReserveSize(size_t size) {
|
bool FileStream::ReserveSize(size_t size) {
|
||||||
// TODO: extend the file to the proper length
|
// TODO: extend the file to the proper length
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -116,10 +116,6 @@ class StreamInterface : public MessageHandler {
|
||||||
// Returns false if the position is not known.
|
// Returns false if the position is not known.
|
||||||
virtual bool GetPosition(size_t* position) const;
|
virtual bool GetPosition(size_t* position) const;
|
||||||
|
|
||||||
// Get the byte length of the entire stream. Returns false if the length
|
|
||||||
// is not known.
|
|
||||||
virtual bool GetSize(size_t* size) const;
|
|
||||||
|
|
||||||
// Return true if flush is successful.
|
// Return true if flush is successful.
|
||||||
virtual bool Flush();
|
virtual bool Flush();
|
||||||
|
|
||||||
|
@ -193,7 +189,6 @@ class StreamAdapterInterface : public StreamInterface,
|
||||||
|
|
||||||
bool SetPosition(size_t position) override;
|
bool SetPosition(size_t position) override;
|
||||||
bool GetPosition(size_t* position) const override;
|
bool GetPosition(size_t* position) const override;
|
||||||
bool GetSize(size_t* size) const override;
|
|
||||||
bool ReserveSize(size_t size) override;
|
bool ReserveSize(size_t size) override;
|
||||||
bool Flush() override;
|
bool Flush() override;
|
||||||
|
|
||||||
|
@ -247,7 +242,6 @@ class FileStream : public StreamInterface {
|
||||||
void Close() override;
|
void Close() override;
|
||||||
bool SetPosition(size_t position) override;
|
bool SetPosition(size_t position) override;
|
||||||
bool GetPosition(size_t* position) const override;
|
bool GetPosition(size_t* position) const override;
|
||||||
bool GetSize(size_t* size) const override;
|
|
||||||
bool ReserveSize(size_t size) override;
|
bool ReserveSize(size_t size) override;
|
||||||
|
|
||||||
bool Flush() override;
|
bool Flush() override;
|
||||||
|
|
|
@ -61,8 +61,6 @@ class TestStream : public StreamInterface {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetSize(size_t* size) const override { return false; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t pos_;
|
size_t pos_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue