OLD | NEW |
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 "content/browser/renderer_host/p2p/socket_host_udp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/common/p2p_messages.h" | 8 #include "content/common/p2p_messages.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 81 |
82 if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN) | 82 if (state_ == STATE_UNINITIALIZED || state_ == STATE_OPEN) |
83 message_sender_->Send(new P2PMsg_OnError(id_)); | 83 message_sender_->Send(new P2PMsg_OnError(id_)); |
84 | 84 |
85 state_ = STATE_ERROR; | 85 state_ = STATE_ERROR; |
86 } | 86 } |
87 | 87 |
88 void P2PSocketHostUdp::DoRead() { | 88 void P2PSocketHostUdp::DoRead() { |
89 int result; | 89 int result; |
90 do { | 90 do { |
91 result = socket_->RecvFrom(recv_buffer_, kReadBufferSize, &recv_address_, | 91 result = socket_-> |
92 base::Bind(&P2PSocketHostUdp::OnRecv, | 92 RecvFrom(recv_buffer_.get(), kReadBufferSize, &recv_address_, |
93 base::Unretained(this))); | 93 base::Bind(&P2PSocketHostUdp::OnRecv, |
| 94 base::Unretained(this))); |
94 DidCompleteRead(result); | 95 DidCompleteRead(result); |
95 } while (result > 0); | 96 } while (result > 0); |
96 } | 97 } |
97 | 98 |
98 void P2PSocketHostUdp::OnRecv(int result) { | 99 void P2PSocketHostUdp::OnRecv(int result) { |
99 DidCompleteRead(result); | 100 DidCompleteRead(result); |
100 if (state_ == STATE_OPEN) { | 101 if (state_ == STATE_OPEN) { |
101 DoRead(); | 102 DoRead(); |
102 } | 103 } |
103 } | 104 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 156 } |
156 send_queue_.push_back(PendingPacket(to, data)); | 157 send_queue_.push_back(PendingPacket(to, data)); |
157 send_queue_bytes_ += data.size(); | 158 send_queue_bytes_ += data.size(); |
158 } else { | 159 } else { |
159 PendingPacket packet(to, data); | 160 PendingPacket packet(to, data); |
160 DoSend(packet); | 161 DoSend(packet); |
161 } | 162 } |
162 } | 163 } |
163 | 164 |
164 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { | 165 void P2PSocketHostUdp::DoSend(const PendingPacket& packet) { |
165 int result = socket_->SendTo(packet.data, packet.size, packet.to, | 166 int result = socket_->SendTo(packet.data.get(), packet.size, packet.to, |
166 base::Bind(&P2PSocketHostUdp::OnSend, | 167 base::Bind(&P2PSocketHostUdp::OnSend, |
167 base::Unretained(this))); | 168 base::Unretained(this))); |
168 if (result == net::ERR_IO_PENDING) { | 169 if (result == net::ERR_IO_PENDING) { |
169 send_pending_ = true; | 170 send_pending_ = true; |
170 } else if (result < 0) { | 171 } else if (result < 0) { |
171 LOG(ERROR) << "Error when sending data in UDP socket: " << result; | 172 LOG(ERROR) << "Error when sending data in UDP socket: " << result; |
172 OnError(); | 173 OnError(); |
173 } | 174 } |
174 } | 175 } |
175 | 176 |
(...skipping 21 matching lines...) Expand all Loading... |
197 } | 198 } |
198 | 199 |
199 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( | 200 P2PSocketHost* P2PSocketHostUdp::AcceptIncomingTcpConnection( |
200 const net::IPEndPoint& remote_address, int id) { | 201 const net::IPEndPoint& remote_address, int id) { |
201 NOTREACHED(); | 202 NOTREACHED(); |
202 OnError(); | 203 OnError(); |
203 return NULL; | 204 return NULL; |
204 } | 205 } |
205 | 206 |
206 } // namespace content | 207 } // namespace content |
OLD | NEW |