blob: 09f7faab2afac911c039d81d78647aae5dee4ab9 [file] [log] [blame]
tkchin93411912015-07-22 12:12:17 -07001/*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_base/filerotatingstream.h"
tkchin93411912015-07-22 12:12:17 -070012
13#include <algorithm>
Jonas Olsson55378f42018-05-25 10:23:10 +020014#include <cstdio>
tkchin93411912015-07-22 12:12:17 -070015#include <string>
Yves Gerey988cc082018-10-23 12:03:01 +020016#include <utility>
tkchin93411912015-07-22 12:12:17 -070017
Niels Möller7b3c76b2018-11-07 09:54:28 +010018#if defined(WEBRTC_WIN)
19#include <windows.h>
20#include "rtc_base/stringutils.h"
21#else
Niels Möller260770c2018-11-07 15:08:18 +010022#include <dirent.h>
Niels Möller7b3c76b2018-11-07 09:54:28 +010023#include <sys/stat.h>
Niels Möllerb7396662018-11-13 11:55:19 +010024#include <unistd.h>
Niels Möller7b3c76b2018-11-07 09:54:28 +010025#endif // WEBRTC_WIN
26
27#include "absl/strings/match.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/checks.h"
Yves Gerey2e00abc2018-10-05 15:39:24 +020030#include "rtc_base/logging.h"
tkchin93411912015-07-22 12:12:17 -070031
Jonas Olsson55378f42018-05-25 10:23:10 +020032// Note: We use fprintf for logging in the write paths of this stream to avoid
tkchin93411912015-07-22 12:12:17 -070033// infinite loops when logging.
34
35namespace rtc {
36
Niels Möller7b3c76b2018-11-07 09:54:28 +010037namespace {
38
Niels Möllerd9ac0582019-01-03 14:21:38 +010039const char kCallSessionLogPrefix[] = "webrtc_log";
40
Niels Möller7b3c76b2018-11-07 09:54:28 +010041std::string AddTrailingPathDelimiterIfNeeded(std::string directory);
Niels Möller260770c2018-11-07 15:08:18 +010042
43// |dir| must have a trailing delimiter. |prefix| must not include wild card
44// characters.
45std::vector<std::string> GetFilesWithPrefix(const std::string& directory,
46 const std::string& prefix);
47bool DeleteFile(const std::string& file);
48bool MoveFile(const std::string& old_file, const std::string& new_file);
49bool IsFile(const std::string& file);
Niels Möller7b3c76b2018-11-07 09:54:28 +010050bool IsFolder(const std::string& file);
Niels Möller260770c2018-11-07 15:08:18 +010051absl::optional<size_t> GetFileSize(const std::string& file);
Niels Möller7b3c76b2018-11-07 09:54:28 +010052
53#if defined(WEBRTC_WIN)
54
55std::string AddTrailingPathDelimiterIfNeeded(std::string directory) {
56 if (absl::EndsWith(directory, "\\")) {
57 return directory;
58 }
59 return directory + "\\";
60}
61
Niels Möller260770c2018-11-07 15:08:18 +010062std::vector<std::string> GetFilesWithPrefix(const std::string& directory,
63 const std::string& prefix) {
64 RTC_DCHECK(absl::EndsWith(directory, "\\"));
65 WIN32_FIND_DATA data;
66 HANDLE handle;
67 handle = ::FindFirstFile(ToUtf16(directory + prefix + '*').c_str(), &data);
68 if (handle == INVALID_HANDLE_VALUE)
69 return {};
70
71 std::vector<std::string> file_list;
72 do {
73 file_list.emplace_back(directory + ToUtf8(data.cFileName));
74 } while (::FindNextFile(handle, &data) == TRUE);
75
76 ::FindClose(handle);
77 return file_list;
78}
79
80bool DeleteFile(const std::string& file) {
81 return ::DeleteFile(ToUtf16(file).c_str()) != 0;
82}
83
84bool MoveFile(const std::string& old_file, const std::string& new_file) {
85 return ::MoveFile(ToUtf16(old_file).c_str(), ToUtf16(new_file).c_str()) != 0;
86}
87
88bool IsFile(const std::string& file) {
89 WIN32_FILE_ATTRIBUTE_DATA data = {0};
90 if (0 == ::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard,
91 &data))
92 return false;
93 return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
94}
95
Niels Möller7b3c76b2018-11-07 09:54:28 +010096bool IsFolder(const std::string& file) {
97 WIN32_FILE_ATTRIBUTE_DATA data = {0};
98 if (0 == ::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard,
99 &data))
100 return false;
101 return (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==
102 FILE_ATTRIBUTE_DIRECTORY;
103}
104
Niels Möller260770c2018-11-07 15:08:18 +0100105absl::optional<size_t> GetFileSize(const std::string& file) {
106 WIN32_FILE_ATTRIBUTE_DATA data = {0};
107 if (::GetFileAttributesEx(ToUtf16(file).c_str(), GetFileExInfoStandard,
108 &data) == 0)
109 return absl::nullopt;
110 return data.nFileSizeLow;
111}
112
Niels Möller7b3c76b2018-11-07 09:54:28 +0100113#else // defined(WEBRTC_WIN)
114
115std::string AddTrailingPathDelimiterIfNeeded(std::string directory) {
116 if (absl::EndsWith(directory, "/")) {
117 return directory;
118 }
119 return directory + "/";
120}
121
Niels Möller260770c2018-11-07 15:08:18 +0100122std::vector<std::string> GetFilesWithPrefix(const std::string& directory,
123 const std::string& prefix) {
124 RTC_DCHECK(absl::EndsWith(directory, "/"));
125 DIR* dir = ::opendir(directory.c_str());
126 if (dir == nullptr)
127 return {};
128 std::vector<std::string> file_list;
129 for (struct dirent* dirent = ::readdir(dir); dirent;
130 dirent = ::readdir(dir)) {
131 std::string name = dirent->d_name;
132 if (name.compare(0, prefix.size(), prefix) == 0) {
133 file_list.emplace_back(directory + name);
134 }
135 }
136 ::closedir(dir);
137 return file_list;
138}
139
140bool DeleteFile(const std::string& file) {
141 return ::unlink(file.c_str()) == 0;
142}
143
144bool MoveFile(const std::string& old_file, const std::string& new_file) {
145 return ::rename(old_file.c_str(), new_file.c_str()) == 0;
146}
147
148bool IsFile(const std::string& file) {
149 struct stat st;
150 int res = ::stat(file.c_str(), &st);
151 // Treat symlinks, named pipes, etc. all as files.
152 return res == 0 && !S_ISDIR(st.st_mode);
153}
154
Niels Möller7b3c76b2018-11-07 09:54:28 +0100155bool IsFolder(const std::string& file) {
156 struct stat st;
157 int res = ::stat(file.c_str(), &st);
158 return res == 0 && S_ISDIR(st.st_mode);
159}
160
Niels Möller260770c2018-11-07 15:08:18 +0100161absl::optional<size_t> GetFileSize(const std::string& file) {
162 struct stat st;
163 if (::stat(file.c_str(), &st) != 0)
164 return absl::nullopt;
165 return st.st_size;
166}
167
Niels Möller7b3c76b2018-11-07 09:54:28 +0100168#endif
169
170} // namespace
171
tkchin93411912015-07-22 12:12:17 -0700172FileRotatingStream::FileRotatingStream(const std::string& dir_path,
173 const std::string& file_prefix)
Yves Gerey665174f2018-06-19 15:03:05 +0200174 : FileRotatingStream(dir_path, file_prefix, 0, 0, kRead) {}
tkchin93411912015-07-22 12:12:17 -0700175
176FileRotatingStream::FileRotatingStream(const std::string& dir_path,
177 const std::string& file_prefix,
178 size_t max_file_size,
179 size_t num_files)
180 : FileRotatingStream(dir_path,
181 file_prefix,
182 max_file_size,
183 num_files,
184 kWrite) {
kwibergaf476c72016-11-28 15:21:39 -0800185 RTC_DCHECK_GT(max_file_size, 0);
186 RTC_DCHECK_GT(num_files, 1);
tkchin93411912015-07-22 12:12:17 -0700187}
188
189FileRotatingStream::FileRotatingStream(const std::string& dir_path,
190 const std::string& file_prefix,
191 size_t max_file_size,
192 size_t num_files,
193 Mode mode)
Niels Möller7b3c76b2018-11-07 09:54:28 +0100194 : dir_path_(AddTrailingPathDelimiterIfNeeded(dir_path)),
tkchin93411912015-07-22 12:12:17 -0700195 file_prefix_(file_prefix),
196 mode_(mode),
197 file_stream_(nullptr),
198 max_file_size_(max_file_size),
199 current_file_index_(0),
200 rotation_index_(0),
201 current_bytes_written_(0),
202 disable_buffering_(false) {
Niels Möller7b3c76b2018-11-07 09:54:28 +0100203 RTC_DCHECK(IsFolder(dir_path));
tkchin93411912015-07-22 12:12:17 -0700204 switch (mode) {
205 case kWrite: {
206 file_names_.clear();
207 for (size_t i = 0; i < num_files; ++i) {
208 file_names_.push_back(GetFilePath(i, num_files));
209 }
210 rotation_index_ = num_files - 1;
211 break;
212 }
213 case kRead: {
Niels Möller260770c2018-11-07 15:08:18 +0100214 file_names_ = GetFilesWithPrefix(dir_path_, file_prefix_);
tkchin93411912015-07-22 12:12:17 -0700215 std::sort(file_names_.begin(), file_names_.end());
216 if (file_names_.size() > 0) {
217 // |file_names_| is sorted newest first, so read from the end.
218 current_file_index_ = file_names_.size() - 1;
219 }
220 break;
221 }
222 }
223}
224
Yves Gerey665174f2018-06-19 15:03:05 +0200225FileRotatingStream::~FileRotatingStream() {}
tkchin93411912015-07-22 12:12:17 -0700226
227StreamState FileRotatingStream::GetState() const {
228 if (mode_ == kRead && current_file_index_ < file_names_.size()) {
229 return SS_OPEN;
230 }
231 if (!file_stream_) {
232 return SS_CLOSED;
233 }
234 return file_stream_->GetState();
235}
236
237StreamResult FileRotatingStream::Read(void* buffer,
238 size_t buffer_len,
239 size_t* read,
240 int* error) {
henrikg91d6ede2015-09-17 00:24:34 -0700241 RTC_DCHECK(buffer);
tkchin93411912015-07-22 12:12:17 -0700242 if (mode_ != kRead) {
243 return SR_EOS;
244 }
245 if (current_file_index_ >= file_names_.size()) {
246 return SR_EOS;
247 }
248 // We will have no file stream initially, and when we are finished with the
249 // previous file.
250 if (!file_stream_) {
251 if (!OpenCurrentFile()) {
252 return SR_ERROR;
253 }
254 }
255 int local_error = 0;
256 if (!error) {
257 error = &local_error;
258 }
259 StreamResult result = file_stream_->Read(buffer, buffer_len, read, error);
260 if (result == SR_EOS || result == SR_ERROR) {
261 if (result == SR_ERROR) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100262 RTC_LOG(LS_ERROR) << "Failed to read from: "
263 << file_names_[current_file_index_]
264 << "Error: " << error;
tkchin93411912015-07-22 12:12:17 -0700265 }
266 // Reached the end of the file, read next file. If there is an error return
267 // the error status but allow for a next read by reading next file.
268 CloseCurrentFile();
269 if (current_file_index_ == 0) {
270 // Just finished reading the last file, signal EOS by setting index.
271 current_file_index_ = file_names_.size();
272 } else {
273 --current_file_index_;
274 }
275 if (read) {
276 *read = 0;
277 }
278 return result == SR_EOS ? SR_SUCCESS : result;
279 } else if (result == SR_SUCCESS) {
280 // Succeeded, continue reading from this file.
281 return SR_SUCCESS;
282 } else {
283 RTC_NOTREACHED();
284 }
285 return result;
286}
287
288StreamResult FileRotatingStream::Write(const void* data,
289 size_t data_len,
290 size_t* written,
291 int* error) {
292 if (mode_ != kWrite) {
293 return SR_EOS;
294 }
295 if (!file_stream_) {
Jonas Olsson55378f42018-05-25 10:23:10 +0200296 std::fprintf(stderr, "Open() must be called before Write.\n");
tkchin93411912015-07-22 12:12:17 -0700297 return SR_ERROR;
298 }
299 // Write as much as will fit in to the current file.
henrikg91d6ede2015-09-17 00:24:34 -0700300 RTC_DCHECK_LT(current_bytes_written_, max_file_size_);
tkchin93411912015-07-22 12:12:17 -0700301 size_t remaining_bytes = max_file_size_ - current_bytes_written_;
302 size_t write_length = std::min(data_len, remaining_bytes);
303 size_t local_written = 0;
304 if (!written) {
305 written = &local_written;
306 }
307 StreamResult result = file_stream_->Write(data, write_length, written, error);
308 current_bytes_written_ += *written;
309
310 // If we're done with this file, rotate it out.
311 if (current_bytes_written_ >= max_file_size_) {
henrikg91d6ede2015-09-17 00:24:34 -0700312 RTC_DCHECK_EQ(current_bytes_written_, max_file_size_);
tkchin93411912015-07-22 12:12:17 -0700313 RotateFiles();
314 }
315 return result;
316}
317
318bool FileRotatingStream::Flush() {
319 if (!file_stream_) {
320 return false;
321 }
322 return file_stream_->Flush();
323}
324
tkchin28bae022015-07-23 12:27:02 -0700325bool FileRotatingStream::GetSize(size_t* size) const {
326 if (mode_ != kRead) {
327 // Not possible to get accurate size on disk when writing because of
328 // potential buffering.
329 return false;
330 }
henrikg91d6ede2015-09-17 00:24:34 -0700331 RTC_DCHECK(size);
tkchin28bae022015-07-23 12:27:02 -0700332 *size = 0;
333 size_t total_size = 0;
334 for (auto file_name : file_names_) {
Niels Möller260770c2018-11-07 15:08:18 +0100335 total_size += GetFileSize(file_name).value_or(0);
tkchin28bae022015-07-23 12:27:02 -0700336 }
337 *size = total_size;
338 return true;
339}
340
tkchin93411912015-07-22 12:12:17 -0700341void FileRotatingStream::Close() {
342 CloseCurrentFile();
343}
344
345bool FileRotatingStream::Open() {
346 switch (mode_) {
347 case kRead:
348 // Defer opening to when we first read since we want to return read error
349 // if we fail to open next file.
350 return true;
351 case kWrite: {
352 // Delete existing files when opening for write.
Niels Möller260770c2018-11-07 15:08:18 +0100353 std::vector<std::string> matching_files =
354 GetFilesWithPrefix(dir_path_, file_prefix_);
355 for (const auto& matching_file : matching_files) {
356 if (!DeleteFile(matching_file)) {
Jonas Olsson55378f42018-05-25 10:23:10 +0200357 std::fprintf(stderr, "Failed to delete: %s\n", matching_file.c_str());
tkchin93411912015-07-22 12:12:17 -0700358 }
359 }
360 return OpenCurrentFile();
361 }
362 }
363 return false;
364}
365
366bool FileRotatingStream::DisableBuffering() {
367 disable_buffering_ = true;
368 if (!file_stream_) {
Jonas Olsson55378f42018-05-25 10:23:10 +0200369 std::fprintf(stderr, "Open() must be called before DisableBuffering().\n");
tkchin93411912015-07-22 12:12:17 -0700370 return false;
371 }
372 return file_stream_->DisableBuffering();
373}
374
375std::string FileRotatingStream::GetFilePath(size_t index) const {
henrikg91d6ede2015-09-17 00:24:34 -0700376 RTC_DCHECK_LT(index, file_names_.size());
tkchin93411912015-07-22 12:12:17 -0700377 return file_names_[index];
378}
379
380bool FileRotatingStream::OpenCurrentFile() {
381 CloseCurrentFile();
382
383 // Opens the appropriate file in the appropriate mode.
henrikg91d6ede2015-09-17 00:24:34 -0700384 RTC_DCHECK_LT(current_file_index_, file_names_.size());
tkchin93411912015-07-22 12:12:17 -0700385 std::string file_path = file_names_[current_file_index_];
386 file_stream_.reset(new FileStream());
387 const char* mode = nullptr;
388 switch (mode_) {
389 case kWrite:
390 mode = "w+";
391 // We should always we writing to the zero-th file.
kwibergaf476c72016-11-28 15:21:39 -0800392 RTC_DCHECK_EQ(current_file_index_, 0);
tkchin93411912015-07-22 12:12:17 -0700393 break;
394 case kRead:
395 mode = "r";
396 break;
397 }
398 int error = 0;
399 if (!file_stream_->Open(file_path, mode, &error)) {
Jonas Olsson55378f42018-05-25 10:23:10 +0200400 std::fprintf(stderr, "Failed to open: %s Error: %i\n", file_path.c_str(),
401 error);
tkchin93411912015-07-22 12:12:17 -0700402 file_stream_.reset();
403 return false;
404 }
405 if (disable_buffering_) {
406 file_stream_->DisableBuffering();
407 }
408 return true;
409}
410
411void FileRotatingStream::CloseCurrentFile() {
412 if (!file_stream_) {
413 return;
414 }
415 current_bytes_written_ = 0;
416 file_stream_.reset();
417}
418
419void FileRotatingStream::RotateFiles() {
henrikg91d6ede2015-09-17 00:24:34 -0700420 RTC_DCHECK_EQ(mode_, kWrite);
tkchin93411912015-07-22 12:12:17 -0700421 CloseCurrentFile();
422 // Rotates the files by deleting the file at |rotation_index_|, which is the
423 // oldest file and then renaming the newer files to have an incremented index.
424 // See header file comments for example.
hayscd02b0fa2015-12-08 13:59:05 -0800425 RTC_DCHECK_LT(rotation_index_, file_names_.size());
tkchin93411912015-07-22 12:12:17 -0700426 std::string file_to_delete = file_names_[rotation_index_];
Niels Möller260770c2018-11-07 15:08:18 +0100427 if (IsFile(file_to_delete)) {
428 if (!DeleteFile(file_to_delete)) {
Jonas Olsson55378f42018-05-25 10:23:10 +0200429 std::fprintf(stderr, "Failed to delete: %s\n", file_to_delete.c_str());
tkchin93411912015-07-22 12:12:17 -0700430 }
431 }
432 for (auto i = rotation_index_; i > 0; --i) {
433 std::string rotated_name = file_names_[i];
434 std::string unrotated_name = file_names_[i - 1];
Niels Möller260770c2018-11-07 15:08:18 +0100435 if (IsFile(unrotated_name)) {
436 if (!MoveFile(unrotated_name, rotated_name)) {
Jonas Olsson55378f42018-05-25 10:23:10 +0200437 std::fprintf(stderr, "Failed to move: %s to %s\n",
438 unrotated_name.c_str(), rotated_name.c_str());
tkchin93411912015-07-22 12:12:17 -0700439 }
440 }
441 }
442 // Create a new file for 0th index.
443 OpenCurrentFile();
444 OnRotation();
445}
446
tkchin93411912015-07-22 12:12:17 -0700447std::string FileRotatingStream::GetFilePath(size_t index,
448 size_t num_files) const {
henrikg91d6ede2015-09-17 00:24:34 -0700449 RTC_DCHECK_LT(index, num_files);
tkchin93411912015-07-22 12:12:17 -0700450
Jonas Olsson671cae22018-06-14 09:57:39 +0200451 const size_t buffer_size = 32;
452 char file_postfix[buffer_size];
453 // We want to zero pad the index so that it will sort nicely.
454 const int max_digits = std::snprintf(nullptr, 0, "%zu", num_files - 1);
455 RTC_DCHECK_LT(1 + max_digits, buffer_size);
456 std::snprintf(file_postfix, buffer_size, "_%0*zu", max_digits, index);
tkchin93411912015-07-22 12:12:17 -0700457
Niels Möller7b3c76b2018-11-07 09:54:28 +0100458 return dir_path_ + file_prefix_ + file_postfix;
tkchin93411912015-07-22 12:12:17 -0700459}
460
461CallSessionFileRotatingStream::CallSessionFileRotatingStream(
462 const std::string& dir_path)
Niels Möllerd9ac0582019-01-03 14:21:38 +0100463 : FileRotatingStream(dir_path, kCallSessionLogPrefix),
tkchin93411912015-07-22 12:12:17 -0700464 max_total_log_size_(0),
Yves Gerey665174f2018-06-19 15:03:05 +0200465 num_rotations_(0) {}
tkchin93411912015-07-22 12:12:17 -0700466
467CallSessionFileRotatingStream::CallSessionFileRotatingStream(
468 const std::string& dir_path,
469 size_t max_total_log_size)
470 : FileRotatingStream(dir_path,
Niels Möllerd9ac0582019-01-03 14:21:38 +0100471 kCallSessionLogPrefix,
tkchin93411912015-07-22 12:12:17 -0700472 max_total_log_size / 2,
473 GetNumRotatingLogFiles(max_total_log_size) + 1),
474 max_total_log_size_(max_total_log_size),
475 num_rotations_(0) {
kwibergaf476c72016-11-28 15:21:39 -0800476 RTC_DCHECK_GE(max_total_log_size, 4);
tkchin93411912015-07-22 12:12:17 -0700477}
478
tkchin93411912015-07-22 12:12:17 -0700479const size_t CallSessionFileRotatingStream::kRotatingLogFileDefaultSize =
480 1024 * 1024;
481
482void CallSessionFileRotatingStream::OnRotation() {
483 ++num_rotations_;
484 if (num_rotations_ == 1) {
485 // On the first rotation adjust the max file size so subsequent files after
486 // the first are smaller.
487 SetMaxFileSize(GetRotatingLogSize(max_total_log_size_));
488 } else if (num_rotations_ == (GetNumFiles() - 1)) {
489 // On the next rotation the very first file is going to be deleted. Change
490 // the rotation index so this doesn't happen.
491 SetRotationIndex(GetRotationIndex() - 1);
492 }
493}
494
495size_t CallSessionFileRotatingStream::GetRotatingLogSize(
496 size_t max_total_log_size) {
497 size_t num_rotating_log_files = GetNumRotatingLogFiles(max_total_log_size);
498 size_t rotating_log_size = num_rotating_log_files > 2
499 ? kRotatingLogFileDefaultSize
500 : max_total_log_size / 4;
501 return rotating_log_size;
502}
503
504size_t CallSessionFileRotatingStream::GetNumRotatingLogFiles(
505 size_t max_total_log_size) {
506 // At minimum have two rotating files. Otherwise split the available log size
507 // evenly across 1MB files.
508 return std::max((size_t)2,
509 (max_total_log_size / 2) / kRotatingLogFileDefaultSize);
510}
511
Niels Möllerd9ac0582019-01-03 14:21:38 +0100512FileRotatingStreamReader::FileRotatingStreamReader(
513 const std::string& dir_path,
514 const std::string& file_prefix) {
515 file_names_ = GetFilesWithPrefix(AddTrailingPathDelimiterIfNeeded(dir_path),
516 file_prefix);
517
518 // Plain sort of the file names would sort by age, i.e., oldest last. Using
519 // std::greater gives us the desired chronological older, oldest first.
520 std::sort(file_names_.begin(), file_names_.end(),
521 std::greater<std::string>());
522}
523
524FileRotatingStreamReader::~FileRotatingStreamReader() = default;
525
526size_t FileRotatingStreamReader::GetSize() const {
527 size_t total_size = 0;
528 for (const auto& file_name : file_names_) {
529 total_size += GetFileSize(file_name).value_or(0);
530 }
531 return total_size;
532}
533
534size_t FileRotatingStreamReader::ReadAll(void* buffer, size_t size) const {
535 size_t done = 0;
536 for (const auto& file_name : file_names_) {
537 if (done < size) {
538 FILE* f = fopen(file_name.c_str(), "rb");
539 if (!f) {
540 break;
541 }
542 done += fread(static_cast<char*>(buffer) + done, 1, size - done, f);
543 fclose(f);
544 } else {
545 break;
546 }
547 }
548 return done;
549}
550
551CallSessionFileRotatingStreamReader::CallSessionFileRotatingStreamReader(
552 const std::string& dir_path)
553 : FileRotatingStreamReader(dir_path, kCallSessionLogPrefix) {}
554
tkchin93411912015-07-22 12:12:17 -0700555} // namespace rtc