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

Unified Diff: net/spdy/spdy_protocol.h

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 side-by-side diff with in-line comments
Download patch
Index: net/spdy/spdy_protocol.h
diff --git a/net/spdy/spdy_protocol.h b/net/spdy/spdy_protocol.h
index cb094565ab9e4ce965cf5794ac979fed7d420428..111c64757c118b113a4d00f020005dcc3174d229 100644
--- a/net/spdy/spdy_protocol.h
+++ b/net/spdy/spdy_protocol.h
@@ -575,17 +575,17 @@ class SpdyFrame {
void set_flags(uint8 flags) { frame_->flags_length_.flags_[0] = flags; }
uint32 length() const {
- return ntohl(frame_->flags_length_.length_) & kLengthMask;
+ return base::NetToHost32(frame_->flags_length_.length_) & kLengthMask;
}
void set_length(uint32 length) {
DCHECK_EQ(0u, (length & ~kLengthMask));
- length = htonl(length & kLengthMask);
+ length = base::HostToNet32(length & kLengthMask);
frame_->flags_length_.length_ = flags() | length;
}
bool is_control_frame() const {
- return (ntohs(frame_->control_.version_) & kControlFlagMask) ==
+ return (base::NetToHost16(frame_->control_.version_) & kControlFlagMask) ==
kControlFlagMask;
}
@@ -611,7 +611,7 @@ class SpdyDataFrame : public SpdyFrame {
: SpdyFrame(data, owns_buffer) {}
SpdyStreamId stream_id() const {
- return ntohl(frame_->data_.stream_id_) & kStreamIdMask;
+ return base::NetToHost32(frame_->data_.stream_id_) & kStreamIdMask;
}
// Note that setting the stream id sets the control bit to false.
@@ -619,7 +619,7 @@ class SpdyDataFrame : public SpdyFrame {
// should always be set correctly.
void set_stream_id(SpdyStreamId id) {
DCHECK_EQ(0u, (id & ~kStreamIdMask));
- frame_->data_.stream_id_ = htonl(id & kStreamIdMask);
+ frame_->data_.stream_id_ = base::HostToNet32(id & kStreamIdMask);
}
// Returns the size of the SpdyFrameBlock structure.
@@ -645,7 +645,7 @@ class SpdyControlFrame : public SpdyFrame {
// frame. Does not guarantee that there are no errors.
bool AppearsToBeAValidControlFrame() const {
// Right now we only check if the frame has an out-of-bounds type.
- uint16 type = ntohs(block()->control_.type_);
+ uint16 type = base::NetToHost16(block()->control_.type_);
// NOOP is not a 'valid' control frame in SPDY/3 and beyond.
return type >= SYN_STREAM &&
type < NUM_CONTROL_FRAME_TYPES &&
@@ -654,17 +654,18 @@ class SpdyControlFrame : public SpdyFrame {
uint16 version() const {
const int kVersionMask = 0x7fff;
- return ntohs(block()->control_.version_) & kVersionMask;
+ return base::NetToHost16(block()->control_.version_) & kVersionMask;
}
void set_version(uint16 version) {
const uint16 kControlBit = 0x80;
DCHECK_EQ(0, version & kControlBit);
- mutable_block()->control_.version_ = kControlBit | htons(version);
+ mutable_block()->control_.version_ =
+ kControlBit | base::HostToNet16(version);
}
SpdyControlType type() const {
- uint16 type = ntohs(block()->control_.type_);
+ uint16 type = base::NetToHost16(block()->control_.type_);
LOG_IF(DFATAL, type < SYN_STREAM || type >= NUM_CONTROL_FRAME_TYPES)
<< "Invalid control frame type " << type;
return static_cast<SpdyControlType>(type);
@@ -672,7 +673,7 @@ class SpdyControlFrame : public SpdyFrame {
void set_type(SpdyControlType type) {
DCHECK(type >= SYN_STREAM && type < NUM_CONTROL_FRAME_TYPES);
- mutable_block()->control_.type_ = htons(type);
+ mutable_block()->control_.type_ = base::HostToNet16(type);
}
// Returns true if this control frame is of a type that has a header block,
@@ -699,19 +700,20 @@ class SpdySynStreamControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
SpdyStreamId stream_id() const {
- return ntohl(block()->stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->stream_id_) & kStreamIdMask;
}
void set_stream_id(SpdyStreamId id) {
- mutable_block()->stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask);
}
SpdyStreamId associated_stream_id() const {
- return ntohl(block()->associated_stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->associated_stream_id_) & kStreamIdMask;
}
void set_associated_stream_id(SpdyStreamId id) {
- mutable_block()->associated_stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->associated_stream_id_ =
+ base::HostToNet32(id & kStreamIdMask);
}
SpdyPriority priority() const {
@@ -753,11 +755,11 @@ class SpdySynReplyControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
SpdyStreamId stream_id() const {
- return ntohl(block()->stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->stream_id_) & kStreamIdMask;
}
void set_stream_id(SpdyStreamId id) {
- mutable_block()->stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask);
}
int header_block_len() const {
@@ -800,23 +802,23 @@ class SpdyRstStreamControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
SpdyStreamId stream_id() const {
- return ntohl(block()->stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->stream_id_) & kStreamIdMask;
}
void set_stream_id(SpdyStreamId id) {
- mutable_block()->stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask);
}
SpdyStatusCodes status() const {
SpdyStatusCodes status =
- static_cast<SpdyStatusCodes>(ntohl(block()->status_));
+ static_cast<SpdyStatusCodes>(base::NetToHost32(block()->status_));
if (status < INVALID || status >= NUM_STATUS_CODES) {
status = INVALID;
}
return status;
}
void set_status(SpdyStatusCodes status) {
- mutable_block()->status_ = htonl(static_cast<uint32>(status));
+ mutable_block()->status_ = base::HostToNet32(static_cast<uint32>(status));
}
// Returns the size of the SpdyRstStreamControlFrameBlock structure.
@@ -840,11 +842,11 @@ class SpdySettingsControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
uint32 num_entries() const {
- return ntohl(block()->num_entries_);
+ return base::NetToHost32(block()->num_entries_);
}
void set_num_entries(int val) {
- mutable_block()->num_entries_ = htonl(val);
+ mutable_block()->num_entries_ = base::HostToNet32(val);
}
int header_block_len() const {
@@ -876,11 +878,11 @@ class SpdyPingControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
uint32 unique_id() const {
- return ntohl(block()->unique_id_);
+ return base::NetToHost32(block()->unique_id_);
}
void set_unique_id(uint32 unique_id) {
- mutable_block()->unique_id_ = htonl(unique_id);
+ mutable_block()->unique_id_ = base::HostToNet32(unique_id);
}
static size_t size() { return sizeof(SpdyPingControlFrameBlock); }
@@ -920,11 +922,12 @@ class SpdyGoAwayControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
SpdyStreamId last_accepted_stream_id() const {
- return ntohl(block()->last_accepted_stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->last_accepted_stream_id_) & kStreamIdMask;
}
void set_last_accepted_stream_id(SpdyStreamId id) {
- mutable_block()->last_accepted_stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->last_accepted_stream_id_ =
+ base::HostToNet32(id & kStreamIdMask);
}
static size_t size() { return sizeof(SpdyGoAwayControlFrameBlock); }
@@ -947,11 +950,11 @@ class SpdyHeadersControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
SpdyStreamId stream_id() const {
- return ntohl(block()->stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->stream_id_) & kStreamIdMask;
}
void set_stream_id(SpdyStreamId id) {
- mutable_block()->stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask);
}
// The number of bytes in the header block beyond the frame header length.
@@ -995,19 +998,19 @@ class SpdyWindowUpdateControlFrame : public SpdyControlFrame {
: SpdyControlFrame(data, owns_buffer) {}
SpdyStreamId stream_id() const {
- return ntohl(block()->stream_id_) & kStreamIdMask;
+ return base::NetToHost32(block()->stream_id_) & kStreamIdMask;
}
void set_stream_id(SpdyStreamId id) {
- mutable_block()->stream_id_ = htonl(id & kStreamIdMask);
+ mutable_block()->stream_id_ = base::HostToNet32(id & kStreamIdMask);
}
uint32 delta_window_size() const {
- return ntohl(block()->delta_window_size_);
+ return base::NetToHost32(block()->delta_window_size_);
}
void set_delta_window_size(uint32 delta_window_size) {
- mutable_block()->delta_window_size_ = htonl(delta_window_size);
+ mutable_block()->delta_window_size_ = base::HostToNet32(delta_window_size);
}
// Returns the size of the SpdyWindowUpdateControlFrameBlock structure.

Powered by Google App Engine
This is Rietveld 408576698