OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "remoting/protocol/buffered_socket_writer.h" | 5 #include "remoting/protocol/buffered_socket_writer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 DISALLOW_COPY_AND_ASSIGN(PendingPacket); | 36 DISALLOW_COPY_AND_ASSIGN(PendingPacket); |
37 }; | 37 }; |
38 | 38 |
39 BufferedSocketWriterBase::BufferedSocketWriterBase( | 39 BufferedSocketWriterBase::BufferedSocketWriterBase( |
40 base::MessageLoopProxy* message_loop) | 40 base::MessageLoopProxy* message_loop) |
41 : buffer_size_(0), | 41 : buffer_size_(0), |
42 socket_(NULL), | 42 socket_(NULL), |
43 message_loop_(message_loop), | 43 message_loop_(message_loop), |
44 write_pending_(false), | 44 write_pending_(false), |
45 ALLOW_THIS_IN_INITIALIZER_LIST( | |
46 written_callback_(this, &BufferedSocketWriterBase::OnWritten)), | |
47 closed_(false) { | 45 closed_(false) { |
48 } | 46 } |
49 | 47 |
50 BufferedSocketWriterBase::~BufferedSocketWriterBase() { } | 48 BufferedSocketWriterBase::~BufferedSocketWriterBase() { } |
51 | 49 |
52 void BufferedSocketWriterBase::Init(net::Socket* socket, | 50 void BufferedSocketWriterBase::Init(net::Socket* socket, |
53 const WriteFailedCallback& callback) { | 51 const WriteFailedCallback& callback) { |
54 DCHECK(message_loop_->BelongsToCurrentThread()); | 52 DCHECK(message_loop_->BelongsToCurrentThread()); |
55 DCHECK(socket); | 53 DCHECK(socket); |
56 socket_ = socket; | 54 socket_ = socket; |
(...skipping 29 matching lines...) Expand all Loading... |
86 int current_packet_size; | 84 int current_packet_size; |
87 { | 85 { |
88 base::AutoLock auto_lock(lock_); | 86 base::AutoLock auto_lock(lock_); |
89 GetNextPacket_Locked(¤t_packet, ¤t_packet_size); | 87 GetNextPacket_Locked(¤t_packet, ¤t_packet_size); |
90 } | 88 } |
91 | 89 |
92 // Return if the queue is empty. | 90 // Return if the queue is empty. |
93 if (!current_packet) | 91 if (!current_packet) |
94 return; | 92 return; |
95 | 93 |
96 int result = socket_->Write(current_packet, current_packet_size, | 94 int result = socket_->Write( |
97 &written_callback_); | 95 current_packet, current_packet_size, |
| 96 base::Bind(&BufferedSocketWriterBase::OnWritten, |
| 97 base::Unretained(this))); |
98 if (result >= 0) { | 98 if (result >= 0) { |
99 base::AutoLock auto_lock(lock_); | 99 base::AutoLock auto_lock(lock_); |
100 AdvanceBufferPosition_Locked(result); | 100 AdvanceBufferPosition_Locked(result); |
101 } else { | 101 } else { |
102 if (result == net::ERR_IO_PENDING) { | 102 if (result == net::ERR_IO_PENDING) { |
103 write_pending_ = true; | 103 write_pending_ = true; |
104 } else { | 104 } else { |
105 HandleError(result); | 105 HandleError(result); |
106 if (!write_failed_callback_.is_null()) | 106 if (!write_failed_callback_.is_null()) |
107 write_failed_callback_.Run(result); | 107 write_failed_callback_.Run(result); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 buffer_size_ -= queue_.front()->data()->size(); | 224 buffer_size_ -= queue_.front()->data()->size(); |
225 PopQueue(); | 225 PopQueue(); |
226 } | 226 } |
227 | 227 |
228 void BufferedDatagramWriter::OnError_Locked(int result) { | 228 void BufferedDatagramWriter::OnError_Locked(int result) { |
229 // Nothing to do here. | 229 // Nothing to do here. |
230 } | 230 } |
231 | 231 |
232 } // namespace protocol | 232 } // namespace protocol |
233 } // namespace remoting | 233 } // namespace remoting |
OLD | NEW |