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

Side by Side Diff: net/spdy/spdy_frame_reader.cc

Issue 9716020: Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch a few remaining call-sites. Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <limits> 5 #include <limits>
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "net/spdy/spdy_frame_reader.h" 8 #include "net/spdy/spdy_frame_reader.h"
9 9
10 namespace spdy { 10 namespace spdy {
11 11
12 SpdyFrameReader::SpdyFrameReader(const char* data, const size_t len) 12 SpdyFrameReader::SpdyFrameReader(const char* data, const size_t len)
13 : data_(data), 13 : data_(data),
14 len_(len), 14 len_(len),
15 ofs_(0) { 15 ofs_(0) {
16 } 16 }
17 17
18 bool SpdyFrameReader::ReadUInt16(uint16* result) { 18 bool SpdyFrameReader::ReadUInt16(uint16* result) {
19 // Make sure that we have the whole uint16. 19 // Make sure that we have the whole uint16.
20 if (!CanRead(2)) { 20 if (!CanRead(2)) {
21 OnFailure(); 21 OnFailure();
22 return false; 22 return false;
23 } 23 }
24 24
25 // Read into result. 25 // Read into result.
26 *result = ntohs(*(reinterpret_cast<const uint16*>(data_ + ofs_))); 26 *result = base::NetToHost16(*(reinterpret_cast<const uint16*>(data_ + ofs_)));
27 27
28 // Iterate. 28 // Iterate.
29 ofs_ += 2; 29 ofs_ += 2;
30 30
31 return true; 31 return true;
32 } 32 }
33 33
34 bool SpdyFrameReader::ReadUInt32(uint32* result) { 34 bool SpdyFrameReader::ReadUInt32(uint32* result) {
35 // Make sure that we have the whole uint32. 35 // Make sure that we have the whole uint32.
36 if (!CanRead(4)) { 36 if (!CanRead(4)) {
37 OnFailure(); 37 OnFailure();
38 return false; 38 return false;
39 } 39 }
40 40
41 // Read into result. 41 // Read into result.
42 *result = ntohl(*(reinterpret_cast<const uint32*>(data_ + ofs_))); 42 *result = base::NetToHost32(*(reinterpret_cast<const uint32*>(data_ + ofs_)));
43 43
44 // Iterate. 44 // Iterate.
45 ofs_ += 4; 45 ofs_ += 4;
46 46
47 return true; 47 return true;
48 } 48 }
49 49
50 bool SpdyFrameReader::ReadStringPiece16(base::StringPiece* result) { 50 bool SpdyFrameReader::ReadStringPiece16(base::StringPiece* result) {
51 // Read resultant length. 51 // Read resultant length.
52 uint16 result_len; 52 uint16 result_len;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return bytes <= (len_ - ofs_); 117 return bytes <= (len_ - ofs_);
118 } 118 }
119 119
120 void SpdyFrameReader::OnFailure() { 120 void SpdyFrameReader::OnFailure() {
121 // Set our iterator to the end of the buffer so that further reads fail 121 // Set our iterator to the end of the buffer so that further reads fail
122 // immediately. 122 // immediately.
123 ofs_ = len_; 123 ofs_ = len_;
124 } 124 }
125 125
126 } // namespace spdy 126 } // namespace spdy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698