| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ | 5 #ifndef MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
| 6 #define MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ | 6 #define MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "mojo/services/network/public/interfaces/udp_socket.mojom.h" | 12 #include "mojo/services/network/public/interfaces/udp_socket.mojom.h" |
| 13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
| 14 #include "net/udp/udp_socket.h" | 14 #include "net/udp/udp_socket.h" |
| 15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" | 15 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h" |
| 16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 class IOBuffer; | 19 class IOBuffer; |
| 19 class IOBufferWithSize; | 20 class IOBufferWithSize; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace mojo { | 23 namespace mojo { |
| 23 | 24 |
| 24 class UDPSocketImpl : public InterfaceImpl<UDPSocket> { | 25 class UDPSocketImpl : public UDPSocket { |
| 25 public: | 26 public: |
| 26 UDPSocketImpl(); | 27 // The lifetime of a new UDPSocketImpl is bound to the connection associated |
| 28 // with |request|. |
| 29 explicit UDPSocketImpl(InterfaceRequest<UDPSocket> request); |
| 27 ~UDPSocketImpl() override; | 30 ~UDPSocketImpl() override; |
| 28 | 31 |
| 29 // UDPSocket implementation. | 32 // UDPSocket implementation. |
| 30 void AllowAddressReuse( | 33 void AllowAddressReuse( |
| 31 const Callback<void(NetworkErrorPtr)>& callback) override; | 34 const Callback<void(NetworkErrorPtr)>& callback) override; |
| 32 | 35 |
| 33 void Bind( | 36 void Bind(NetAddressPtr addr, |
| 34 NetAddressPtr addr, | 37 const Callback<void(NetworkErrorPtr, |
| 35 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; | 38 NetAddressPtr, |
| 39 InterfaceRequest<UDPSocketReceiver>)>& callback) |
| 40 override; |
| 36 | 41 |
| 37 void Connect( | 42 void Connect(NetAddressPtr remote_addr, |
| 38 NetAddressPtr remote_addr, | 43 const Callback<void(NetworkErrorPtr, |
| 39 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; | 44 NetAddressPtr, |
| 45 InterfaceRequest<UDPSocketReceiver>)>& |
| 46 callback) override; |
| 40 | 47 |
| 41 void SetSendBufferSize( | 48 void SetSendBufferSize( |
| 42 uint32_t size, | 49 uint32_t size, |
| 43 const Callback<void(NetworkErrorPtr)>& callback) override; | 50 const Callback<void(NetworkErrorPtr)>& callback) override; |
| 44 | 51 |
| 45 void SetReceiveBufferSize( | 52 void SetReceiveBufferSize( |
| 46 uint32_t size, | 53 uint32_t size, |
| 47 const Callback<void(NetworkErrorPtr)>& callback) override; | 54 const Callback<void(NetworkErrorPtr)>& callback) override; |
| 48 | 55 |
| 49 void NegotiateMaxPendingSendRequests( | 56 void NegotiateMaxPendingSendRequests( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 const Callback<void(NetworkErrorPtr)>& callback); | 85 const Callback<void(NetworkErrorPtr)>& callback); |
| 79 | 86 |
| 80 void OnRecvFromCompleted(int net_result); | 87 void OnRecvFromCompleted(int net_result); |
| 81 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback, | 88 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback, |
| 82 int net_result); | 89 int net_result); |
| 83 | 90 |
| 84 bool IsBoundOrConnected() const { | 91 bool IsBoundOrConnected() const { |
| 85 return state_ == BOUND || state_ == CONNECTED; | 92 return state_ == BOUND || state_ == CONNECTED; |
| 86 } | 93 } |
| 87 | 94 |
| 95 StrongBinding<UDPSocket> binding_; |
| 96 |
| 88 net::UDPSocket socket_; | 97 net::UDPSocket socket_; |
| 89 | 98 |
| 90 State state_; | 99 State state_; |
| 91 | 100 |
| 92 bool allow_address_reuse_; | 101 bool allow_address_reuse_; |
| 93 | 102 |
| 94 // Non-null when there is a pending RecvFrom operation on |socket_|. | 103 // Non-null when there is a pending RecvFrom operation on |socket_|. |
| 95 scoped_refptr<net::IOBuffer> recvfrom_buffer_; | 104 scoped_refptr<net::IOBuffer> recvfrom_buffer_; |
| 96 // Non-null when there is a pending SendTo operation on |socket_|. | 105 // Non-null when there is a pending SendTo operation on |socket_|. |
| 97 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; | 106 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; |
| 98 | 107 |
| 108 // The address of the pending RecvFrom operation, if any. |
| 99 net::IPEndPoint recvfrom_address_; | 109 net::IPEndPoint recvfrom_address_; |
| 100 | 110 |
| 111 // The interface which gets data from fulfilled receive requests. |
| 112 UDPSocketReceiverPtr receiver_; |
| 113 |
| 101 // How many more packets the client side expects to receive. | 114 // How many more packets the client side expects to receive. |
| 102 size_t remaining_recv_slots_; | 115 size_t remaining_recv_slots_; |
| 103 | 116 |
| 104 // The queue owns the PendingSendRequest instances. | 117 // The queue owns the PendingSendRequest instances. |
| 105 std::deque<PendingSendRequest*> pending_send_requests_; | 118 std::deque<PendingSendRequest*> pending_send_requests_; |
| 106 // The maximum size of the |pending_send_requests_| queue. | 119 // The maximum size of the |pending_send_requests_| queue. |
| 107 size_t max_pending_send_requests_; | 120 size_t max_pending_send_requests_; |
| 108 | 121 |
| 109 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); | 122 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); |
| 110 }; | 123 }; |
| 111 | 124 |
| 112 } // namespace mojo | 125 } // namespace mojo |
| 113 | 126 |
| 114 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ | 127 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
| OLD | NEW |