Delete unused class FileStream
Unused since cl https://webrtc-review.googlesource.com/c/117620 Bug: webrtc:6463 Change-Id: I35a20ba56637968e3dd1d8231b98737d60bdfe75 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128900 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27734}
This commit is contained in:
parent
5d54f1feef
commit
6cab98e305
@ -18,13 +18,6 @@
|
||||
#include "rtc_base/stream.h"
|
||||
#include "rtc_base/thread.h"
|
||||
|
||||
#if defined(WEBRTC_WIN)
|
||||
#include <windows.h>
|
||||
|
||||
#define fileno _fileno
|
||||
#include "rtc_base/string_utils.h"
|
||||
#endif
|
||||
|
||||
namespace rtc {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -137,134 +130,5 @@ void StreamAdapterInterface::OnEvent(StreamInterface* stream,
|
||||
SignalEvent(this, events, err);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FileStream
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
FileStream::FileStream() : file_(nullptr) {}
|
||||
|
||||
FileStream::~FileStream() {
|
||||
FileStream::Close();
|
||||
}
|
||||
|
||||
bool FileStream::Open(const std::string& filename,
|
||||
const char* mode,
|
||||
int* error) {
|
||||
Close();
|
||||
#if defined(WEBRTC_WIN)
|
||||
std::wstring wfilename;
|
||||
if (Utf8ToWindowsFilename(filename, &wfilename)) {
|
||||
file_ = _wfopen(wfilename.c_str(), ToUtf16(mode).c_str());
|
||||
} else {
|
||||
if (error) {
|
||||
*error = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
file_ = fopen(filename.c_str(), mode);
|
||||
#endif
|
||||
if (!file_ && error) {
|
||||
*error = errno;
|
||||
}
|
||||
return (file_ != nullptr);
|
||||
}
|
||||
|
||||
bool FileStream::OpenShare(const std::string& filename,
|
||||
const char* mode,
|
||||
int shflag,
|
||||
int* error) {
|
||||
Close();
|
||||
#if defined(WEBRTC_WIN)
|
||||
std::wstring wfilename;
|
||||
if (Utf8ToWindowsFilename(filename, &wfilename)) {
|
||||
file_ = _wfsopen(wfilename.c_str(), ToUtf16(mode).c_str(), shflag);
|
||||
if (!file_ && error) {
|
||||
*error = errno;
|
||||
return false;
|
||||
}
|
||||
return file_ != nullptr;
|
||||
} else {
|
||||
if (error) {
|
||||
*error = -1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return Open(filename, mode, error);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileStream::DisableBuffering() {
|
||||
if (!file_)
|
||||
return false;
|
||||
return (setvbuf(file_, nullptr, _IONBF, 0) == 0);
|
||||
}
|
||||
|
||||
StreamState FileStream::GetState() const {
|
||||
return (file_ == nullptr) ? SS_CLOSED : SS_OPEN;
|
||||
}
|
||||
|
||||
StreamResult FileStream::Read(void* buffer,
|
||||
size_t buffer_len,
|
||||
size_t* read,
|
||||
int* error) {
|
||||
if (!file_)
|
||||
return SR_EOS;
|
||||
size_t result = fread(buffer, 1, buffer_len, file_);
|
||||
if ((result == 0) && (buffer_len > 0)) {
|
||||
if (feof(file_))
|
||||
return SR_EOS;
|
||||
if (error)
|
||||
*error = errno;
|
||||
return SR_ERROR;
|
||||
}
|
||||
if (read)
|
||||
*read = result;
|
||||
return SR_SUCCESS;
|
||||
}
|
||||
|
||||
StreamResult FileStream::Write(const void* data,
|
||||
size_t data_len,
|
||||
size_t* written,
|
||||
int* error) {
|
||||
if (!file_)
|
||||
return SR_EOS;
|
||||
size_t result = fwrite(data, 1, data_len, file_);
|
||||
if ((result == 0) && (data_len > 0)) {
|
||||
if (error)
|
||||
*error = errno;
|
||||
return SR_ERROR;
|
||||
}
|
||||
if (written)
|
||||
*written = result;
|
||||
return SR_SUCCESS;
|
||||
}
|
||||
|
||||
void FileStream::Close() {
|
||||
if (file_) {
|
||||
DoClose();
|
||||
file_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool FileStream::SetPosition(size_t position) {
|
||||
if (!file_)
|
||||
return false;
|
||||
return (fseek(file_, static_cast<int>(position), SEEK_SET) == 0);
|
||||
}
|
||||
|
||||
bool FileStream::Flush() {
|
||||
if (file_) {
|
||||
return (0 == fflush(file_));
|
||||
}
|
||||
// try to flush empty file?
|
||||
RTC_NOTREACHED();
|
||||
return false;
|
||||
}
|
||||
|
||||
void FileStream::DoClose() {
|
||||
fclose(file_);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
@ -11,8 +11,6 @@
|
||||
#ifndef RTC_BASE_STREAM_H_
|
||||
#define RTC_BASE_STREAM_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "rtc_base/buffer.h"
|
||||
@ -180,51 +178,6 @@ class StreamAdapterInterface : public StreamInterface,
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamAdapterInterface);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FileStream is a simple implementation of a StreamInterface, which does not
|
||||
// support asynchronous notification.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO(bugs.webrtc.org/6463): Delete this class.
|
||||
class FileStream : public StreamInterface {
|
||||
public:
|
||||
FileStream();
|
||||
~FileStream() override;
|
||||
|
||||
// The semantics of filename and mode are the same as stdio's fopen
|
||||
virtual bool Open(const std::string& filename, const char* mode, int* error);
|
||||
virtual bool OpenShare(const std::string& filename,
|
||||
const char* mode,
|
||||
int shflag,
|
||||
int* error);
|
||||
|
||||
// By default, reads and writes are buffered for efficiency. Disabling
|
||||
// buffering causes writes to block until the bytes on disk are updated.
|
||||
virtual bool DisableBuffering();
|
||||
|
||||
StreamState GetState() const override;
|
||||
StreamResult Read(void* buffer,
|
||||
size_t buffer_len,
|
||||
size_t* read,
|
||||
int* error) override;
|
||||
StreamResult Write(const void* data,
|
||||
size_t data_len,
|
||||
size_t* written,
|
||||
int* error) override;
|
||||
void Close() override;
|
||||
virtual bool SetPosition(size_t position);
|
||||
|
||||
bool Flush() override;
|
||||
|
||||
protected:
|
||||
virtual void DoClose();
|
||||
|
||||
FILE* file_;
|
||||
|
||||
private:
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(FileStream);
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_STREAM_H_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user