Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: webrtc/base/stream.cc

Issue 2718663005: Replace NULL with nullptr or null in webrtc/base/. (Closed)
Patch Set: Fixing Windows and formatting issues. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/stream.h ('k') | webrtc/base/stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (read) 71 if (read)
72 *read = total_read; 72 *read = total_read;
73 return result; 73 return result;
74 } 74 }
75 75
76 StreamResult StreamInterface::ReadLine(std::string* line) { 76 StreamResult StreamInterface::ReadLine(std::string* line) {
77 line->clear(); 77 line->clear();
78 StreamResult result = SR_SUCCESS; 78 StreamResult result = SR_SUCCESS;
79 while (true) { 79 while (true) {
80 char ch; 80 char ch;
81 result = Read(&ch, sizeof(ch), NULL, NULL); 81 result = Read(&ch, sizeof(ch), nullptr, nullptr);
82 if (result != SR_SUCCESS) { 82 if (result != SR_SUCCESS) {
83 break; 83 break;
84 } 84 }
85 if (ch == '\n') { 85 if (ch == '\n') {
86 break; 86 break;
87 } 87 }
88 line->push_back(ch); 88 line->push_back(ch);
89 } 89 }
90 if (!line->empty()) { // give back the line we've collected so far with 90 if (!line->empty()) { // give back the line we've collected so far with
91 result = SR_SUCCESS; // a success code. Otherwise return the last code 91 result = SR_SUCCESS; // a success code. Otherwise return the last code
92 } 92 }
93 return result; 93 return result;
94 } 94 }
95 95
96 void StreamInterface::PostEvent(Thread* t, int events, int err) { 96 void StreamInterface::PostEvent(Thread* t, int events, int err) {
97 t->Post(RTC_FROM_HERE, this, MSG_POST_EVENT, 97 t->Post(RTC_FROM_HERE, this, MSG_POST_EVENT,
98 new StreamEventData(events, err)); 98 new StreamEventData(events, err));
99 } 99 }
100 100
101 void StreamInterface::PostEvent(int events, int err) { 101 void StreamInterface::PostEvent(int events, int err) {
102 PostEvent(Thread::Current(), events, err); 102 PostEvent(Thread::Current(), events, err);
103 } 103 }
104 104
105 const void* StreamInterface::GetReadData(size_t* data_len) { 105 const void* StreamInterface::GetReadData(size_t* data_len) {
106 return NULL; 106 return nullptr;
107 } 107 }
108 108
109 void* StreamInterface::GetWriteBuffer(size_t* buf_len) { 109 void* StreamInterface::GetWriteBuffer(size_t* buf_len) {
110 return NULL; 110 return nullptr;
111 } 111 }
112 112
113 bool StreamInterface::SetPosition(size_t position) { 113 bool StreamInterface::SetPosition(size_t position) {
114 return false; 114 return false;
115 } 115 }
116 116
117 bool StreamInterface::GetPosition(size_t* position) const { 117 bool StreamInterface::GetPosition(size_t* position) const {
118 return false; 118 return false;
119 } 119 }
120 120
(...skipping 28 matching lines...) Expand all
149 } 149 }
150 } 150 }
151 151
152 /////////////////////////////////////////////////////////////////////////////// 152 ///////////////////////////////////////////////////////////////////////////////
153 // StreamAdapterInterface 153 // StreamAdapterInterface
154 /////////////////////////////////////////////////////////////////////////////// 154 ///////////////////////////////////////////////////////////////////////////////
155 155
156 StreamAdapterInterface::StreamAdapterInterface(StreamInterface* stream, 156 StreamAdapterInterface::StreamAdapterInterface(StreamInterface* stream,
157 bool owned) 157 bool owned)
158 : stream_(stream), owned_(owned) { 158 : stream_(stream), owned_(owned) {
159 if (NULL != stream_) 159 if (nullptr != stream_)
160 stream_->SignalEvent.connect(this, &StreamAdapterInterface::OnEvent); 160 stream_->SignalEvent.connect(this, &StreamAdapterInterface::OnEvent);
161 } 161 }
162 162
163 StreamState StreamAdapterInterface::GetState() const { 163 StreamState StreamAdapterInterface::GetState() const {
164 return stream_->GetState(); 164 return stream_->GetState();
165 } 165 }
166 StreamResult StreamAdapterInterface::Read(void* buffer, 166 StreamResult StreamAdapterInterface::Read(void* buffer,
167 size_t buffer_len, 167 size_t buffer_len,
168 size_t* read, 168 size_t* read,
169 int* error) { 169 int* error) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 bool StreamAdapterInterface::ReserveSize(size_t size) { 202 bool StreamAdapterInterface::ReserveSize(size_t size) {
203 return stream_->ReserveSize(size); 203 return stream_->ReserveSize(size);
204 } 204 }
205 205
206 bool StreamAdapterInterface::Flush() { 206 bool StreamAdapterInterface::Flush() {
207 return stream_->Flush(); 207 return stream_->Flush();
208 } 208 }
209 209
210 void StreamAdapterInterface::Attach(StreamInterface* stream, bool owned) { 210 void StreamAdapterInterface::Attach(StreamInterface* stream, bool owned) {
211 if (NULL != stream_) 211 if (nullptr != stream_)
212 stream_->SignalEvent.disconnect(this); 212 stream_->SignalEvent.disconnect(this);
213 if (owned_) 213 if (owned_)
214 delete stream_; 214 delete stream_;
215 stream_ = stream; 215 stream_ = stream;
216 owned_ = owned; 216 owned_ = owned;
217 if (NULL != stream_) 217 if (nullptr != stream_)
218 stream_->SignalEvent.connect(this, &StreamAdapterInterface::OnEvent); 218 stream_->SignalEvent.connect(this, &StreamAdapterInterface::OnEvent);
219 } 219 }
220 220
221 StreamInterface* StreamAdapterInterface::Detach() { 221 StreamInterface* StreamAdapterInterface::Detach() {
222 if (NULL != stream_) 222 if (nullptr != stream_)
223 stream_->SignalEvent.disconnect(this); 223 stream_->SignalEvent.disconnect(this);
224 StreamInterface* stream = stream_; 224 StreamInterface* stream = stream_;
225 stream_ = NULL; 225 stream_ = nullptr;
226 return stream; 226 return stream;
227 } 227 }
228 228
229 StreamAdapterInterface::~StreamAdapterInterface() { 229 StreamAdapterInterface::~StreamAdapterInterface() {
230 if (owned_) 230 if (owned_)
231 delete stream_; 231 delete stream_;
232 } 232 }
233 233
234 void StreamAdapterInterface::OnEvent(StreamInterface* stream, 234 void StreamAdapterInterface::OnEvent(StreamInterface* stream,
235 int events, 235 int events,
(...skipping 30 matching lines...) Expand all
266 266
267 StreamResult StreamTap::Read(void* buffer, size_t buffer_len, 267 StreamResult StreamTap::Read(void* buffer, size_t buffer_len,
268 size_t* read, int* error) { 268 size_t* read, int* error) {
269 size_t backup_read; 269 size_t backup_read;
270 if (!read) { 270 if (!read) {
271 read = &backup_read; 271 read = &backup_read;
272 } 272 }
273 StreamResult res = StreamAdapterInterface::Read(buffer, buffer_len, 273 StreamResult res = StreamAdapterInterface::Read(buffer, buffer_len,
274 read, error); 274 read, error);
275 if ((res == SR_SUCCESS) && (tap_result_ == SR_SUCCESS)) { 275 if ((res == SR_SUCCESS) && (tap_result_ == SR_SUCCESS)) {
276 tap_result_ = tap_->WriteAll(buffer, *read, NULL, &tap_error_); 276 tap_result_ = tap_->WriteAll(buffer, *read, nullptr, &tap_error_);
277 } 277 }
278 return res; 278 return res;
279 } 279 }
280 280
281 StreamResult StreamTap::Write(const void* data, size_t data_len, 281 StreamResult StreamTap::Write(const void* data, size_t data_len,
282 size_t* written, int* error) { 282 size_t* written, int* error) {
283 size_t backup_written; 283 size_t backup_written;
284 if (!written) { 284 if (!written) {
285 written = &backup_written; 285 written = &backup_written;
286 } 286 }
287 StreamResult res = StreamAdapterInterface::Write(data, data_len, 287 StreamResult res = StreamAdapterInterface::Write(data, data_len,
288 written, error); 288 written, error);
289 if ((res == SR_SUCCESS) && (tap_result_ == SR_SUCCESS)) { 289 if ((res == SR_SUCCESS) && (tap_result_ == SR_SUCCESS)) {
290 tap_result_ = tap_->WriteAll(data, *written, NULL, &tap_error_); 290 tap_result_ = tap_->WriteAll(data, *written, nullptr, &tap_error_);
291 } 291 }
292 return res; 292 return res;
293 } 293 }
294 294
295 /////////////////////////////////////////////////////////////////////////////// 295 ///////////////////////////////////////////////////////////////////////////////
296 // NullStream 296 // NullStream
297 /////////////////////////////////////////////////////////////////////////////// 297 ///////////////////////////////////////////////////////////////////////////////
298 298
299 NullStream::NullStream() { 299 NullStream::NullStream() {
300 } 300 }
(...skipping 17 matching lines...) Expand all
318 return SR_SUCCESS; 318 return SR_SUCCESS;
319 } 319 }
320 320
321 void NullStream::Close() { 321 void NullStream::Close() {
322 } 322 }
323 323
324 /////////////////////////////////////////////////////////////////////////////// 324 ///////////////////////////////////////////////////////////////////////////////
325 // FileStream 325 // FileStream
326 /////////////////////////////////////////////////////////////////////////////// 326 ///////////////////////////////////////////////////////////////////////////////
327 327
328 FileStream::FileStream() : file_(NULL) { 328 FileStream::FileStream() : file_(nullptr) {}
329 }
330 329
331 FileStream::~FileStream() { 330 FileStream::~FileStream() {
332 FileStream::Close(); 331 FileStream::Close();
333 } 332 }
334 333
335 bool FileStream::Open(const std::string& filename, const char* mode, 334 bool FileStream::Open(const std::string& filename, const char* mode,
336 int* error) { 335 int* error) {
337 Close(); 336 Close();
338 #if defined(WEBRTC_WIN) 337 #if defined(WEBRTC_WIN)
339 std::wstring wfilename; 338 std::wstring wfilename;
340 if (Utf8ToWindowsFilename(filename, &wfilename)) { 339 if (Utf8ToWindowsFilename(filename, &wfilename)) {
341 file_ = _wfopen(wfilename.c_str(), ToUtf16(mode).c_str()); 340 file_ = _wfopen(wfilename.c_str(), ToUtf16(mode).c_str());
342 } else { 341 } else {
343 if (error) { 342 if (error) {
344 *error = -1; 343 *error = -1;
345 return false; 344 return false;
346 } 345 }
347 } 346 }
348 #else 347 #else
349 file_ = fopen(filename.c_str(), mode); 348 file_ = fopen(filename.c_str(), mode);
350 #endif 349 #endif
351 if (!file_ && error) { 350 if (!file_ && error) {
352 *error = errno; 351 *error = errno;
353 } 352 }
354 return (file_ != NULL); 353 return (file_ != nullptr);
355 } 354 }
356 355
357 bool FileStream::OpenShare(const std::string& filename, const char* mode, 356 bool FileStream::OpenShare(const std::string& filename, const char* mode,
358 int shflag, int* error) { 357 int shflag, int* error) {
359 Close(); 358 Close();
360 #if defined(WEBRTC_WIN) 359 #if defined(WEBRTC_WIN)
361 std::wstring wfilename; 360 std::wstring wfilename;
362 if (Utf8ToWindowsFilename(filename, &wfilename)) { 361 if (Utf8ToWindowsFilename(filename, &wfilename)) {
363 file_ = _wfsopen(wfilename.c_str(), ToUtf16(mode).c_str(), shflag); 362 file_ = _wfsopen(wfilename.c_str(), ToUtf16(mode).c_str(), shflag);
364 if (!file_ && error) { 363 if (!file_ && error) {
365 *error = errno; 364 *error = errno;
366 return false; 365 return false;
367 } 366 }
368 return file_ != NULL; 367 return file_ != nullptr;
369 } else { 368 } else {
370 if (error) { 369 if (error) {
371 *error = -1; 370 *error = -1;
372 } 371 }
373 return false; 372 return false;
374 } 373 }
375 #else 374 #else
376 return Open(filename, mode, error); 375 return Open(filename, mode, error);
377 #endif 376 #endif
378 } 377 }
379 378
380 bool FileStream::DisableBuffering() { 379 bool FileStream::DisableBuffering() {
381 if (!file_) 380 if (!file_)
382 return false; 381 return false;
383 return (setvbuf(file_, NULL, _IONBF, 0) == 0); 382 return (setvbuf(file_, nullptr, _IONBF, 0) == 0);
384 } 383 }
385 384
386 StreamState FileStream::GetState() const { 385 StreamState FileStream::GetState() const {
387 return (file_ == NULL) ? SS_CLOSED : SS_OPEN; 386 return (file_ == nullptr) ? SS_CLOSED : SS_OPEN;
388 } 387 }
389 388
390 StreamResult FileStream::Read(void* buffer, size_t buffer_len, 389 StreamResult FileStream::Read(void* buffer, size_t buffer_len,
391 size_t* read, int* error) { 390 size_t* read, int* error) {
392 if (!file_) 391 if (!file_)
393 return SR_EOS; 392 return SR_EOS;
394 size_t result = fread(buffer, 1, buffer_len, file_); 393 size_t result = fread(buffer, 1, buffer_len, file_);
395 if ((result == 0) && (buffer_len > 0)) { 394 if ((result == 0) && (buffer_len > 0)) {
396 if (feof(file_)) 395 if (feof(file_))
397 return SR_EOS; 396 return SR_EOS;
(...skipping 17 matching lines...) Expand all
415 return SR_ERROR; 414 return SR_ERROR;
416 } 415 }
417 if (written) 416 if (written)
418 *written = result; 417 *written = result;
419 return SR_SUCCESS; 418 return SR_SUCCESS;
420 } 419 }
421 420
422 void FileStream::Close() { 421 void FileStream::Close() {
423 if (file_) { 422 if (file_) {
424 DoClose(); 423 DoClose();
425 file_ = NULL; 424 file_ = nullptr;
426 } 425 }
427 } 426 }
428 427
429 bool FileStream::SetPosition(size_t position) { 428 bool FileStream::SetPosition(size_t position) {
430 if (!file_) 429 if (!file_)
431 return false; 430 return false;
432 return (fseek(file_, static_cast<int>(position), SEEK_SET) == 0); 431 return (fseek(file_, static_cast<int>(position), SEEK_SET) == 0);
433 } 432 }
434 433
435 bool FileStream::GetPosition(size_t* position) const { 434 bool FileStream::GetPosition(size_t* position) const {
436 RTC_DCHECK(NULL != position); 435 RTC_DCHECK(nullptr != position);
437 if (!file_) 436 if (!file_)
438 return false; 437 return false;
439 long result = ftell(file_); 438 long result = ftell(file_);
440 if (result < 0) 439 if (result < 0)
441 return false; 440 return false;
442 if (position) 441 if (position)
443 *position = result; 442 *position = result;
444 return true; 443 return true;
445 } 444 }
446 445
447 bool FileStream::GetSize(size_t* size) const { 446 bool FileStream::GetSize(size_t* size) const {
448 RTC_DCHECK(NULL != size); 447 RTC_DCHECK(nullptr != size);
449 if (!file_) 448 if (!file_)
450 return false; 449 return false;
451 struct stat file_stats; 450 struct stat file_stats;
452 if (fstat(fileno(file_), &file_stats) != 0) 451 if (fstat(fileno(file_), &file_stats) != 0)
453 return false; 452 return false;
454 if (size) 453 if (size)
455 *size = file_stats.st_size; 454 *size = file_stats.st_size;
456 return true; 455 return true;
457 } 456 }
458 457
459 bool FileStream::GetAvailable(size_t* size) const { 458 bool FileStream::GetAvailable(size_t* size) const {
460 RTC_DCHECK(NULL != size); 459 RTC_DCHECK(nullptr != size);
461 if (!GetSize(size)) 460 if (!GetSize(size))
462 return false; 461 return false;
463 long result = ftell(file_); 462 long result = ftell(file_);
464 if (result < 0) 463 if (result < 0)
465 return false; 464 return false;
466 if (size) 465 if (size)
467 *size -= result; 466 *size -= result;
468 return true; 467 return true;
469 } 468 }
470 469
(...skipping 15 matching lines...) Expand all
486 return (0 == fflush(file_)); 485 return (0 == fflush(file_));
487 } 486 }
488 // try to flush empty file? 487 // try to flush empty file?
489 RTC_NOTREACHED(); 488 RTC_NOTREACHED();
490 return false; 489 return false;
491 } 490 }
492 491
493 #if defined(WEBRTC_POSIX) && !defined(__native_client__) 492 #if defined(WEBRTC_POSIX) && !defined(__native_client__)
494 493
495 bool FileStream::TryLock() { 494 bool FileStream::TryLock() {
496 if (file_ == NULL) { 495 if (file_ == nullptr) {
497 // Stream not open. 496 // Stream not open.
498 RTC_NOTREACHED(); 497 RTC_NOTREACHED();
499 return false; 498 return false;
500 } 499 }
501 500
502 return flock(fileno(file_), LOCK_EX|LOCK_NB) == 0; 501 return flock(fileno(file_), LOCK_EX|LOCK_NB) == 0;
503 } 502 }
504 503
505 bool FileStream::Unlock() { 504 bool FileStream::Unlock() {
506 if (file_ == NULL) { 505 if (file_ == nullptr) {
507 // Stream not open. 506 // Stream not open.
508 RTC_NOTREACHED(); 507 RTC_NOTREACHED();
509 return false; 508 return false;
510 } 509 }
511 510
512 return flock(fileno(file_), LOCK_UN) == 0; 511 return flock(fileno(file_), LOCK_UN) == 0;
513 } 512 }
514 513
515 #endif 514 #endif
516 515
517 void FileStream::DoClose() { 516 void FileStream::DoClose() {
518 fclose(file_); 517 fclose(file_);
519 } 518 }
520 519
521 /////////////////////////////////////////////////////////////////////////////// 520 ///////////////////////////////////////////////////////////////////////////////
522 // MemoryStream 521 // MemoryStream
523 /////////////////////////////////////////////////////////////////////////////// 522 ///////////////////////////////////////////////////////////////////////////////
524 523
525 MemoryStreamBase::MemoryStreamBase() 524 MemoryStreamBase::MemoryStreamBase()
526 : buffer_(NULL), buffer_length_(0), data_length_(0), 525 : buffer_(nullptr), buffer_length_(0), data_length_(0), seek_position_(0) {}
527 seek_position_(0) {
528 }
529 526
530 StreamState MemoryStreamBase::GetState() const { 527 StreamState MemoryStreamBase::GetState() const {
531 return SS_OPEN; 528 return SS_OPEN;
532 } 529 }
533 530
534 StreamResult MemoryStreamBase::Read(void* buffer, size_t bytes, 531 StreamResult MemoryStreamBase::Read(void* buffer, size_t bytes,
535 size_t* bytes_read, int* error) { 532 size_t* bytes_read, int* error) {
536 if (seek_position_ >= data_length_) { 533 if (seek_position_ >= data_length_) {
537 return SR_EOS; 534 return SR_EOS;
538 } 535 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 return true; 600 return true;
604 } 601 }
605 602
606 bool MemoryStreamBase::GetAvailable(size_t* size) const { 603 bool MemoryStreamBase::GetAvailable(size_t* size) const {
607 if (size) 604 if (size)
608 *size = data_length_ - seek_position_; 605 *size = data_length_ - seek_position_;
609 return true; 606 return true;
610 } 607 }
611 608
612 bool MemoryStreamBase::ReserveSize(size_t size) { 609 bool MemoryStreamBase::ReserveSize(size_t size) {
613 return (SR_SUCCESS == DoReserve(size, NULL)); 610 return (SR_SUCCESS == DoReserve(size, nullptr));
614 } 611 }
615 612
616 StreamResult MemoryStreamBase::DoReserve(size_t size, int* error) { 613 StreamResult MemoryStreamBase::DoReserve(size_t size, int* error) {
617 return (buffer_length_ >= size) ? SR_SUCCESS : SR_EOS; 614 return (buffer_length_ >= size) ? SR_SUCCESS : SR_EOS;
618 } 615 }
619 616
620 /////////////////////////////////////////////////////////////////////////////// 617 ///////////////////////////////////////////////////////////////////////////////
621 618
622 MemoryStream::MemoryStream() 619 MemoryStream::MemoryStream() : buffer_alloc_(nullptr) {}
623 : buffer_alloc_(NULL) {
624 }
625 620
626 MemoryStream::MemoryStream(const char* data) 621 MemoryStream::MemoryStream(const char* data) : buffer_alloc_(nullptr) {
627 : buffer_alloc_(NULL) {
628 SetData(data, strlen(data)); 622 SetData(data, strlen(data));
629 } 623 }
630 624
631 MemoryStream::MemoryStream(const void* data, size_t length) 625 MemoryStream::MemoryStream(const void* data, size_t length)
632 : buffer_alloc_(NULL) { 626 : buffer_alloc_(nullptr) {
633 SetData(data, length); 627 SetData(data, length);
634 } 628 }
635 629
636 MemoryStream::~MemoryStream() { 630 MemoryStream::~MemoryStream() {
637 delete [] buffer_alloc_; 631 delete [] buffer_alloc_;
638 } 632 }
639 633
640 void MemoryStream::SetData(const void* data, size_t length) { 634 void MemoryStream::SetData(const void* data, size_t length) {
641 data_length_ = buffer_length_ = length; 635 data_length_ = buffer_length_ = length;
642 delete [] buffer_alloc_; 636 delete [] buffer_alloc_;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 read_position_ = (read_position_ + size) % buffer_length_; 806 read_position_ = (read_position_ + size) % buffer_length_;
813 data_length_ -= size; 807 data_length_ -= size;
814 if (!was_writable && size > 0) { 808 if (!was_writable && size > 0) {
815 PostEvent(owner_, SE_WRITE, 0); 809 PostEvent(owner_, SE_WRITE, 0);
816 } 810 }
817 } 811 }
818 812
819 void* FifoBuffer::GetWriteBuffer(size_t* size) { 813 void* FifoBuffer::GetWriteBuffer(size_t* size) {
820 CritScope cs(&crit_); 814 CritScope cs(&crit_);
821 if (state_ == SS_CLOSED) { 815 if (state_ == SS_CLOSED) {
822 return NULL; 816 return nullptr;
823 } 817 }
824 818
825 // if empty, reset the write position to the beginning, so we can get 819 // if empty, reset the write position to the beginning, so we can get
826 // the biggest possible block 820 // the biggest possible block
827 if (data_length_ == 0) { 821 if (data_length_ == 0) {
828 read_position_ = 0; 822 read_position_ = 0;
829 } 823 }
830 824
831 const size_t write_position = (read_position_ + data_length_) 825 const size_t write_position = (read_position_ + data_length_)
832 % buffer_length_; 826 % buffer_length_;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 StreamResult result = StreamAdapterInterface::Write(data, data_len, written, 930 StreamResult result = StreamAdapterInterface::Write(data, data_len, written,
937 error); 931 error);
938 if (result == SR_SUCCESS) { 932 if (result == SR_SUCCESS) {
939 LogMultiline(level_, label_.c_str(), false, data, *written, hex_mode_, 933 LogMultiline(level_, label_.c_str(), false, data, *written, hex_mode_,
940 &lms_); 934 &lms_);
941 } 935 }
942 return result; 936 return result;
943 } 937 }
944 938
945 void LoggingAdapter::Close() { 939 void LoggingAdapter::Close() {
946 LogMultiline(level_, label_.c_str(), false, NULL, 0, hex_mode_, &lms_); 940 LogMultiline(level_, label_.c_str(), false, nullptr, 0, hex_mode_, &lms_);
947 LogMultiline(level_, label_.c_str(), true, NULL, 0, hex_mode_, &lms_); 941 LogMultiline(level_, label_.c_str(), true, nullptr, 0, hex_mode_, &lms_);
948 LOG_V(level_) << label_ << " Closed locally"; 942 LOG_V(level_) << label_ << " Closed locally";
949 StreamAdapterInterface::Close(); 943 StreamAdapterInterface::Close();
950 } 944 }
951 945
952 void LoggingAdapter::OnEvent(StreamInterface* stream, int events, int err) { 946 void LoggingAdapter::OnEvent(StreamInterface* stream, int events, int err) {
953 if (events & SE_OPEN) { 947 if (events & SE_OPEN) {
954 LOG_V(level_) << label_ << " Open"; 948 LOG_V(level_) << label_ << " Open";
955 } else if (events & SE_CLOSE) { 949 } else if (events & SE_CLOSE) {
956 LogMultiline(level_, label_.c_str(), false, NULL, 0, hex_mode_, &lms_); 950 LogMultiline(level_, label_.c_str(), false, nullptr, 0, hex_mode_, &lms_);
957 LogMultiline(level_, label_.c_str(), true, NULL, 0, hex_mode_, &lms_); 951 LogMultiline(level_, label_.c_str(), true, nullptr, 0, hex_mode_, &lms_);
958 LOG_V(level_) << label_ << " Closed with error: " << err; 952 LOG_V(level_) << label_ << " Closed with error: " << err;
959 } 953 }
960 StreamAdapterInterface::OnEvent(stream, events, err); 954 StreamAdapterInterface::OnEvent(stream, events, err);
961 } 955 }
962 956
963 /////////////////////////////////////////////////////////////////////////////// 957 ///////////////////////////////////////////////////////////////////////////////
964 // StringStream - Reads/Writes to an external std::string 958 // StringStream - Reads/Writes to an external std::string
965 /////////////////////////////////////////////////////////////////////////////// 959 ///////////////////////////////////////////////////////////////////////////////
966 960
967 StringStream::StringStream(std::string* str) 961 StringStream::StringStream(std::string* str)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 1053
1060 StreamReference::StreamReference(StreamRefCount* stream_ref_count, 1054 StreamReference::StreamReference(StreamRefCount* stream_ref_count,
1061 StreamInterface* stream) 1055 StreamInterface* stream)
1062 : StreamAdapterInterface(stream, false), 1056 : StreamAdapterInterface(stream, false),
1063 stream_ref_count_(stream_ref_count) { 1057 stream_ref_count_(stream_ref_count) {
1064 } 1058 }
1065 1059
1066 /////////////////////////////////////////////////////////////////////////////// 1060 ///////////////////////////////////////////////////////////////////////////////
1067 1061
1068 StreamResult Flow(StreamInterface* source, 1062 StreamResult Flow(StreamInterface* source,
1069 char* buffer, size_t buffer_len, 1063 char* buffer,
1064 size_t buffer_len,
1070 StreamInterface* sink, 1065 StreamInterface* sink,
1071 size_t* data_len /* = NULL */) { 1066 size_t* data_len /* = nullptr */) {
1072 RTC_DCHECK(buffer_len > 0); 1067 RTC_DCHECK(buffer_len > 0);
1073 1068
1074 StreamResult result; 1069 StreamResult result;
1075 size_t count, read_pos, write_pos; 1070 size_t count, read_pos, write_pos;
1076 if (data_len) { 1071 if (data_len) {
1077 read_pos = *data_len; 1072 read_pos = *data_len;
1078 } else { 1073 } else {
1079 read_pos = 0; 1074 read_pos = 0;
1080 } 1075 }
1081 1076
1082 bool end_of_stream = false; 1077 bool end_of_stream = false;
1083 do { 1078 do {
1084 // Read until buffer is full, end of stream, or error 1079 // Read until buffer is full, end of stream, or error
1085 while (!end_of_stream && (read_pos < buffer_len)) { 1080 while (!end_of_stream && (read_pos < buffer_len)) {
1086 result = source->Read(buffer + read_pos, buffer_len - read_pos, 1081 result = source->Read(buffer + read_pos, buffer_len - read_pos, &count,
1087 &count, NULL); 1082 nullptr);
1088 if (result == SR_EOS) { 1083 if (result == SR_EOS) {
1089 end_of_stream = true; 1084 end_of_stream = true;
1090 } else if (result != SR_SUCCESS) { 1085 } else if (result != SR_SUCCESS) {
1091 if (data_len) { 1086 if (data_len) {
1092 *data_len = read_pos; 1087 *data_len = read_pos;
1093 } 1088 }
1094 return result; 1089 return result;
1095 } else { 1090 } else {
1096 read_pos += count; 1091 read_pos += count;
1097 } 1092 }
1098 } 1093 }
1099 1094
1100 // Write until buffer is empty, or error (including end of stream) 1095 // Write until buffer is empty, or error (including end of stream)
1101 write_pos = 0; 1096 write_pos = 0;
1102 while (write_pos < read_pos) { 1097 while (write_pos < read_pos) {
1103 result = sink->Write(buffer + write_pos, read_pos - write_pos, 1098 result = sink->Write(buffer + write_pos, read_pos - write_pos, &count,
1104 &count, NULL); 1099 nullptr);
1105 if (result != SR_SUCCESS) { 1100 if (result != SR_SUCCESS) {
1106 if (data_len) { 1101 if (data_len) {
1107 *data_len = read_pos - write_pos; 1102 *data_len = read_pos - write_pos;
1108 if (write_pos > 0) { 1103 if (write_pos > 0) {
1109 memmove(buffer, buffer + write_pos, *data_len); 1104 memmove(buffer, buffer + write_pos, *data_len);
1110 } 1105 }
1111 } 1106 }
1112 return result; 1107 return result;
1113 } 1108 }
1114 write_pos += count; 1109 write_pos += count;
1115 } 1110 }
1116 1111
1117 read_pos = 0; 1112 read_pos = 0;
1118 } while (!end_of_stream); 1113 } while (!end_of_stream);
1119 1114
1120 if (data_len) { 1115 if (data_len) {
1121 *data_len = 0; 1116 *data_len = 0;
1122 } 1117 }
1123 return SR_SUCCESS; 1118 return SR_SUCCESS;
1124 } 1119 }
1125 1120
1126 /////////////////////////////////////////////////////////////////////////////// 1121 ///////////////////////////////////////////////////////////////////////////////
1127 1122
1128 } // namespace rtc 1123 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/stream.h ('k') | webrtc/base/stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698