| 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 <deque> | 7 #include <deque> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 virtual int SendTo(net::IOBuffer* buf, int buf_len, | 88 virtual int SendTo(net::IOBuffer* buf, int buf_len, |
| 89 const net::IPEndPoint& address, | 89 const net::IPEndPoint& address, |
| 90 const net::CompletionCallback& callback) OVERRIDE { | 90 const net::CompletionCallback& callback) OVERRIDE { |
| 91 scoped_refptr<net::IOBuffer> buffer(buf); | 91 scoped_refptr<net::IOBuffer> buffer(buf); |
| 92 std::vector<char> data_vector(buffer->data(), buffer->data() + buf_len); | 92 std::vector<char> data_vector(buffer->data(), buffer->data() + buf_len); |
| 93 sent_packets_->push_back(UDPPacket(address, data_vector)); | 93 sent_packets_->push_back(UDPPacket(address, data_vector)); |
| 94 return buf_len; | 94 return buf_len; |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE { | 97 virtual int SetReceiveBufferSize(int32 size) OVERRIDE { |
| 98 return true; | 98 return net::OK; |
| 99 } | 99 } |
| 100 | 100 |
| 101 virtual bool SetSendBufferSize(int32 size) OVERRIDE { | 101 virtual int SetSendBufferSize(int32 size) OVERRIDE { |
| 102 return true; | 102 return net::OK; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) { | 105 void ReceivePacket(const net::IPEndPoint& address, std::vector<char> data) { |
| 106 if (!recv_callback_.is_null()) { | 106 if (!recv_callback_.is_null()) { |
| 107 int size = std::min(recv_size_, static_cast<int>(data.size())); | 107 int size = std::min(recv_size_, static_cast<int>(data.size())); |
| 108 memcpy(recv_buffer_->data(), &*data.begin(), size); | 108 memcpy(recv_buffer_->data(), &*data.begin(), size); |
| 109 *recv_address_ = address; | 109 *recv_address_ = address; |
| 110 net::CompletionCallback cb = recv_callback_; | 110 net::CompletionCallback cb = recv_callback_; |
| 111 recv_callback_.Reset(); | 111 recv_callback_.Reset(); |
| 112 recv_buffer_ = NULL; | 112 recv_buffer_ = NULL; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 socket_host_->Send(dest3, packet1, options, 0); | 380 socket_host_->Send(dest3, packet1, options, 0); |
| 381 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224); | 381 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224); |
| 382 // This packet should also be dropped. | 382 // This packet should also be dropped. |
| 383 socket_host_->Send(dest4, packet1, options, 0); | 383 socket_host_->Send(dest4, packet1, options, 0); |
| 384 // |dest1| is known, we can send as many packets to it. | 384 // |dest1| is known, we can send as many packets to it. |
| 385 socket_host_->Send(dest1_, packet1, options, 0); | 385 socket_host_->Send(dest1_, packet1, options, 0); |
| 386 ASSERT_EQ(sent_packets_.size(), 4U); | 386 ASSERT_EQ(sent_packets_.size(), 4U); |
| 387 } | 387 } |
| 388 | 388 |
| 389 } // namespace content | 389 } // namespace content |
| OLD | NEW |