| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "google_apis/gcm/base/socket_stream.h" | 5 #include "google_apis/gcm/base/socket_stream.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/callback.h" | 10 #include "base/callback.h" |
| 9 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 10 #include "net/socket/stream_socket.h" | 12 #include "net/socket/stream_socket.h" |
| 11 | 13 |
| 12 namespace gcm { | 14 namespace gcm { |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 // TODO(zea): consider having dynamically-sized buffers if this becomes too | 18 // TODO(zea): consider having dynamically-sized buffers if this becomes too |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 DVLOG(1) << "Backing up " << count << " bytes in input buffer. " | 66 DVLOG(1) << "Backing up " << count << " bytes in input buffer. " |
| 65 << "Current position now at " << next_pos_ | 67 << "Current position now at " << next_pos_ |
| 66 << " of " << read_buffer_->BytesConsumed(); | 68 << " of " << read_buffer_->BytesConsumed(); |
| 67 } | 69 } |
| 68 | 70 |
| 69 bool SocketInputStream::Skip(int count) { | 71 bool SocketInputStream::Skip(int count) { |
| 70 NOTIMPLEMENTED(); | 72 NOTIMPLEMENTED(); |
| 71 return false; | 73 return false; |
| 72 } | 74 } |
| 73 | 75 |
| 74 int64 SocketInputStream::ByteCount() const { | 76 int64_t SocketInputStream::ByteCount() const { |
| 75 DCHECK_NE(GetState(), CLOSED); | 77 DCHECK_NE(GetState(), CLOSED); |
| 76 DCHECK_NE(GetState(), READING); | 78 DCHECK_NE(GetState(), READING); |
| 77 return next_pos_; | 79 return next_pos_; |
| 78 } | 80 } |
| 79 | 81 |
| 80 int SocketInputStream::UnreadByteCount() const { | 82 int SocketInputStream::UnreadByteCount() const { |
| 81 DCHECK_NE(GetState(), CLOSED); | 83 DCHECK_NE(GetState(), CLOSED); |
| 82 DCHECK_NE(GetState(), READING); | 84 DCHECK_NE(GetState(), READING); |
| 83 return read_buffer_->BytesConsumed() - next_pos_; | 85 return read_buffer_->BytesConsumed() - next_pos_; |
| 84 } | 86 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 240 |
| 239 void SocketOutputStream::BackUp(int count) { | 241 void SocketOutputStream::BackUp(int count) { |
| 240 DCHECK_GE(count, 0); | 242 DCHECK_GE(count, 0); |
| 241 if (count > next_pos_) | 243 if (count > next_pos_) |
| 242 next_pos_ = 0; | 244 next_pos_ = 0; |
| 243 next_pos_ -= count; | 245 next_pos_ -= count; |
| 244 DVLOG(1) << "Backing up " << count << " bytes in output buffer. " | 246 DVLOG(1) << "Backing up " << count << " bytes in output buffer. " |
| 245 << next_pos_ << " bytes used."; | 247 << next_pos_ << " bytes used."; |
| 246 } | 248 } |
| 247 | 249 |
| 248 int64 SocketOutputStream::ByteCount() const { | 250 int64_t SocketOutputStream::ByteCount() const { |
| 249 DCHECK_NE(GetState(), CLOSED); | 251 DCHECK_NE(GetState(), CLOSED); |
| 250 DCHECK_NE(GetState(), FLUSHING); | 252 DCHECK_NE(GetState(), FLUSHING); |
| 251 return next_pos_; | 253 return next_pos_; |
| 252 } | 254 } |
| 253 | 255 |
| 254 net::Error SocketOutputStream::Flush(const base::Closure& callback) { | 256 net::Error SocketOutputStream::Flush(const base::Closure& callback) { |
| 255 DCHECK_EQ(GetState(), READY); | 257 DCHECK_EQ(GetState(), READY); |
| 256 | 258 |
| 257 if (!socket_->IsConnected()) { | 259 if (!socket_->IsConnected()) { |
| 258 LOG(ERROR) << "Socket was disconnected, closing output stream"; | 260 LOG(ERROR) << "Socket was disconnected, closing output stream"; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 330 } |
| 329 | 331 |
| 330 DVLOG(1) << "Socket flush complete."; | 332 DVLOG(1) << "Socket flush complete."; |
| 331 write_buffer_->SetOffset(0); | 333 write_buffer_->SetOffset(0); |
| 332 next_pos_ = 0; | 334 next_pos_ = 0; |
| 333 if (!callback.is_null()) | 335 if (!callback.is_null()) |
| 334 callback.Run(); | 336 callback.Run(); |
| 335 } | 337 } |
| 336 | 338 |
| 337 } // namespace gcm | 339 } // namespace gcm |
| OLD | NEW |