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

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

Issue 1440193002: Fix DTLS packet boundary handling in SSLStreamAdapterTests. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: No longer inherit BufferQueue from StreamInterface Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 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 20 matching lines...) Expand all
31 CritScope cs(&crit_); 31 CritScope cs(&crit_);
32 return queue_.size(); 32 return queue_.size();
33 } 33 }
34 34
35 bool BufferQueue::ReadFront(void* buffer, size_t bytes, size_t* bytes_read) { 35 bool BufferQueue::ReadFront(void* buffer, size_t bytes, size_t* bytes_read) {
36 CritScope cs(&crit_); 36 CritScope cs(&crit_);
37 if (queue_.empty()) { 37 if (queue_.empty()) {
38 return false; 38 return false;
39 } 39 }
40 40
41 bool was_writable = queue_.size() < capacity_;
41 Buffer* packet = queue_.front(); 42 Buffer* packet = queue_.front();
42 queue_.pop_front(); 43 queue_.pop_front();
43 44
44 size_t next_packet_size = packet->size(); 45 bytes = std::min(bytes, packet->size());
45 if (bytes > next_packet_size) {
46 bytes = next_packet_size;
47 }
48
49 memcpy(buffer, packet->data(), bytes); 46 memcpy(buffer, packet->data(), bytes);
50 if (bytes_read) { 47 if (bytes_read) {
51 *bytes_read = bytes; 48 *bytes_read = bytes;
52 } 49 }
53 free_list_.push_back(packet); 50 free_list_.push_back(packet);
51 if (!was_writable) {
52 NotifyWritableForTest();
53 }
54 return true; 54 return true;
55 } 55 }
56 56
57 bool BufferQueue::WriteBack(const void* buffer, size_t bytes, 57 bool BufferQueue::WriteBack(const void* buffer, size_t bytes,
58 size_t* bytes_written) { 58 size_t* bytes_written) {
59 CritScope cs(&crit_); 59 CritScope cs(&crit_);
60 if (queue_.size() == capacity_) { 60 if (queue_.size() == capacity_) {
61 return false; 61 return false;
62 } 62 }
63 63
64 bool was_readable = !queue_.empty();
64 Buffer* packet; 65 Buffer* packet;
65 if (!free_list_.empty()) { 66 if (!free_list_.empty()) {
66 packet = free_list_.back(); 67 packet = free_list_.back();
67 free_list_.pop_back(); 68 free_list_.pop_back();
68 } else { 69 } else {
69 packet = new Buffer(bytes, default_size_); 70 packet = new Buffer(bytes, default_size_);
70 } 71 }
71 72
72 packet->SetData(static_cast<const uint8_t*>(buffer), bytes); 73 packet->SetData(static_cast<const uint8_t*>(buffer), bytes);
73 if (bytes_written) { 74 if (bytes_written) {
74 *bytes_written = bytes; 75 *bytes_written = bytes;
75 } 76 }
76 queue_.push_back(packet); 77 queue_.push_back(packet);
78 if (!was_readable) {
79 NotifyReadableForTest();
80 }
77 return true; 81 return true;
78 } 82 }
79 83
80 } // namespace rtc 84 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698