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

Side by Side Diff: net/tools/flip_server/ring_buffer.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/flip_server/ring_buffer.h" 5 #include "net/tools/flip_server/ring_buffer.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 7
8 namespace net { 8 namespace net {
9 9
10 RingBuffer::RingBuffer(int buffer_size) 10 RingBuffer::RingBuffer(int buffer_size)
11 : buffer_(new char[buffer_size]), 11 : buffer_(new char[buffer_size]),
12 buffer_size_(buffer_size), 12 buffer_size_(buffer_size),
13 bytes_used_(0), 13 bytes_used_(0),
14 read_idx_(0), 14 read_idx_(0),
15 write_idx_(0) {} 15 write_idx_(0) {
16 }
16 17
17 RingBuffer::~RingBuffer() {} 18 RingBuffer::~RingBuffer() {
19 }
18 20
19 int RingBuffer::ReadableBytes() const { return bytes_used_; } 21 int RingBuffer::ReadableBytes() const {
22 return bytes_used_;
23 }
20 24
21 int RingBuffer::BufferSize() const { return buffer_size_; } 25 int RingBuffer::BufferSize() const {
26 return buffer_size_;
27 }
22 28
23 int RingBuffer::BytesFree() const { return BufferSize() - ReadableBytes(); } 29 int RingBuffer::BytesFree() const {
30 return BufferSize() - ReadableBytes();
31 }
24 32
25 bool RingBuffer::Empty() const { return ReadableBytes() == 0; } 33 bool RingBuffer::Empty() const {
34 return ReadableBytes() == 0;
35 }
26 36
27 bool RingBuffer::Full() const { return ReadableBytes() == BufferSize(); } 37 bool RingBuffer::Full() const {
38 return ReadableBytes() == BufferSize();
39 }
28 40
29 // Returns the number of characters written. 41 // Returns the number of characters written.
30 // Appends up-to-'size' bytes to the ringbuffer. 42 // Appends up-to-'size' bytes to the ringbuffer.
31 int RingBuffer::Write(const char* bytes, int size) { 43 int RingBuffer::Write(const char* bytes, int size) {
32 CHECK_GE(size, 0); 44 CHECK_GE(size, 0);
33 #if 1 45 #if 1
34 char* wptr; 46 char* wptr;
35 int wsize; 47 int wsize;
36 GetWritablePtr(&wptr, &wsize); 48 GetWritablePtr(&wptr, &wsize);
37 int bytes_remaining = size; 49 int bytes_remaining = size;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 244 }
233 buffer_.reset(new_buffer); 245 buffer_.reset(new_buffer);
234 246
235 buffer_size_ = buffer_size; 247 buffer_size_ = buffer_size;
236 bytes_used_ = bytes_used; 248 bytes_used_ = bytes_used;
237 read_idx_ = 0; 249 read_idx_ = 0;
238 write_idx_ = bytes_used_ % buffer_size_; 250 write_idx_ = bytes_used_ % buffer_size_;
239 } 251 }
240 252
241 } // namespace net 253 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698