| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/socket/stream_socket.h" | 10 #include "net/socket/stream_socket.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return net::OK; | 94 return net::OK; |
| 95 } | 95 } |
| 96 | 96 |
| 97 if (!socket_->IsConnected()) { | 97 if (!socket_->IsConnected()) { |
| 98 LOG(ERROR) << "Socket was disconnected, closing input stream"; | 98 LOG(ERROR) << "Socket was disconnected, closing input stream"; |
| 99 CloseStream(net::ERR_CONNECTION_CLOSED, base::Closure()); | 99 CloseStream(net::ERR_CONNECTION_CLOSED, base::Closure()); |
| 100 return net::OK; | 100 return net::OK; |
| 101 } | 101 } |
| 102 | 102 |
| 103 DVLOG(1) << "Refreshing input stream, limit of " << byte_limit << " bytes."; | 103 DVLOG(1) << "Refreshing input stream, limit of " << byte_limit << " bytes."; |
| 104 int result = socket_->Read( | 104 int result = |
| 105 read_buffer_, | 105 socket_->Read(read_buffer_.get(), |
| 106 byte_limit, | 106 byte_limit, |
| 107 base::Bind(&SocketInputStream::RefreshCompletionCallback, | 107 base::Bind(&SocketInputStream::RefreshCompletionCallback, |
| 108 weak_ptr_factory_.GetWeakPtr(), | 108 weak_ptr_factory_.GetWeakPtr(), |
| 109 callback)); | 109 callback)); |
| 110 DVLOG(1) << "Read returned " << result; | 110 DVLOG(1) << "Read returned " << result; |
| 111 if (result == net::ERR_IO_PENDING) { | 111 if (result == net::ERR_IO_PENDING) { |
| 112 last_error_ = net::ERR_IO_PENDING; | 112 last_error_ = net::ERR_IO_PENDING; |
| 113 return net::ERR_IO_PENDING; | 113 return net::ERR_IO_PENDING; |
| 114 } | 114 } |
| 115 | 115 |
| 116 RefreshCompletionCallback(base::Closure(), result); | 116 RefreshCompletionCallback(base::Closure(), result); |
| 117 return net::OK; | 117 return net::OK; |
| 118 } | 118 } |
| 119 | 119 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 net::Error SocketOutputStream::Flush(const base::Closure& callback) { | 249 net::Error SocketOutputStream::Flush(const base::Closure& callback) { |
| 250 DCHECK_EQ(GetState(), READY); | 250 DCHECK_EQ(GetState(), READY); |
| 251 | 251 |
| 252 if (!socket_->IsConnected()) { | 252 if (!socket_->IsConnected()) { |
| 253 LOG(ERROR) << "Socket was disconnected, closing output stream"; | 253 LOG(ERROR) << "Socket was disconnected, closing output stream"; |
| 254 last_error_ = net::ERR_CONNECTION_CLOSED; | 254 last_error_ = net::ERR_CONNECTION_CLOSED; |
| 255 return net::OK; | 255 return net::OK; |
| 256 } | 256 } |
| 257 | 257 |
| 258 DVLOG(1) << "Flushing " << next_pos_ << " bytes into socket."; | 258 DVLOG(1) << "Flushing " << next_pos_ << " bytes into socket."; |
| 259 int result = socket_->Write( | 259 int result = |
| 260 write_buffer_, | 260 socket_->Write(write_buffer_.get(), |
| 261 next_pos_, | 261 next_pos_, |
| 262 base::Bind(&SocketOutputStream::FlushCompletionCallback, | 262 base::Bind(&SocketOutputStream::FlushCompletionCallback, |
| 263 weak_ptr_factory_.GetWeakPtr(), | 263 weak_ptr_factory_.GetWeakPtr(), |
| 264 callback)); | 264 callback)); |
| 265 DVLOG(1) << "Write returned " << result; | 265 DVLOG(1) << "Write returned " << result; |
| 266 if (result == net::ERR_IO_PENDING) { | 266 if (result == net::ERR_IO_PENDING) { |
| 267 last_error_ = net::ERR_IO_PENDING; | 267 last_error_ = net::ERR_IO_PENDING; |
| 268 return net::ERR_IO_PENDING; | 268 return net::ERR_IO_PENDING; |
| 269 } | 269 } |
| 270 | 270 |
| 271 FlushCompletionCallback(base::Closure(), result); | 271 FlushCompletionCallback(base::Closure(), result); |
| 272 return net::OK; | 272 return net::OK; |
| 273 } | 273 } |
| 274 | 274 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 323 } |
| 324 | 324 |
| 325 DVLOG(1) << "Socket flush complete."; | 325 DVLOG(1) << "Socket flush complete."; |
| 326 write_buffer_->SetOffset(0); | 326 write_buffer_->SetOffset(0); |
| 327 next_pos_ = 0; | 327 next_pos_ = 0; |
| 328 if (!callback.is_null()) | 328 if (!callback.is_null()) |
| 329 callback.Run(); | 329 callback.Run(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 } // namespace gcm | 332 } // namespace gcm |
| OLD | NEW |