| 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( |
| 34 NetAddressPtr addr, | 37 NetAddressPtr addr, |
| 35 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; | 38 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; |
| 36 | 39 |
| 37 void Connect( | 40 void Connect( |
| 38 NetAddressPtr remote_addr, | 41 NetAddressPtr remote_addr, |
| 39 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; | 42 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override; |
| 40 | 43 |
| 41 void SetSendBufferSize( | 44 void SetSendBufferSize( |
| 42 uint32_t size, | 45 uint32_t size, |
| 43 const Callback<void(NetworkErrorPtr)>& callback) override; | 46 const Callback<void(NetworkErrorPtr)>& callback) override; |
| 44 | 47 |
| 45 void SetReceiveBufferSize( | 48 void SetReceiveBufferSize( |
| 46 uint32_t size, | 49 uint32_t size, |
| 47 const Callback<void(NetworkErrorPtr)>& callback) override; | 50 const Callback<void(NetworkErrorPtr)>& callback) override; |
| 48 | 51 |
| 49 void NegotiateMaxPendingSendRequests( | 52 void NegotiateMaxPendingSendRequests( |
| 50 uint32_t requested_size, | 53 uint32_t requested_size, |
| 51 const Callback<void(uint32_t)>& callback) override; | 54 const Callback<void(uint32_t)>& callback) override; |
| 52 | 55 |
| 56 void SetReceiver(UDPSocketReceiverPtr receiver) override; |
| 57 |
| 53 void ReceiveMore(uint32_t datagram_number) override; | 58 void ReceiveMore(uint32_t datagram_number) override; |
| 54 | 59 |
| 55 void SendTo(NetAddressPtr dest_addr, | 60 void SendTo(NetAddressPtr dest_addr, |
| 56 Array<uint8_t> data, | 61 Array<uint8_t> data, |
| 57 const Callback<void(NetworkErrorPtr)>& callback) override; | 62 const Callback<void(NetworkErrorPtr)>& callback) override; |
| 58 | 63 |
| 59 private: | 64 private: |
| 60 enum State { | 65 enum State { |
| 61 NOT_BOUND_OR_CONNECTED, | 66 NOT_BOUND_OR_CONNECTED, |
| 62 BOUND, | 67 BOUND, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 const Callback<void(NetworkErrorPtr)>& callback); | 83 const Callback<void(NetworkErrorPtr)>& callback); |
| 79 | 84 |
| 80 void OnRecvFromCompleted(int net_result); | 85 void OnRecvFromCompleted(int net_result); |
| 81 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback, | 86 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback, |
| 82 int net_result); | 87 int net_result); |
| 83 | 88 |
| 84 bool IsBoundOrConnected() const { | 89 bool IsBoundOrConnected() const { |
| 85 return state_ == BOUND || state_ == CONNECTED; | 90 return state_ == BOUND || state_ == CONNECTED; |
| 86 } | 91 } |
| 87 | 92 |
| 93 StrongBinding<UDPSocket> binding_; |
| 94 |
| 88 net::UDPSocket socket_; | 95 net::UDPSocket socket_; |
| 89 | 96 |
| 90 State state_; | 97 State state_; |
| 91 | 98 |
| 92 bool allow_address_reuse_; | 99 bool allow_address_reuse_; |
| 93 | 100 |
| 94 // Non-null when there is a pending RecvFrom operation on |socket_|. | 101 // Non-null when there is a pending RecvFrom operation on |socket_|. |
| 95 scoped_refptr<net::IOBuffer> recvfrom_buffer_; | 102 scoped_refptr<net::IOBuffer> recvfrom_buffer_; |
| 96 // Non-null when there is a pending SendTo operation on |socket_|. | 103 // Non-null when there is a pending SendTo operation on |socket_|. |
| 97 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; | 104 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; |
| 98 | 105 |
| 106 // The address of the pending RecvFrom operation, if any. |
| 99 net::IPEndPoint recvfrom_address_; | 107 net::IPEndPoint recvfrom_address_; |
| 100 | 108 |
| 109 // The result code the pending RecvFrom operation, if any. |
| 110 int recvfrom_result_; |
| 111 |
| 112 // The interface which gets data from fulfilled receive requests. |
| 113 UDPSocketReceiverPtr receiver_; |
| 114 |
| 101 // How many more packets the client side expects to receive. | 115 // How many more packets the client side expects to receive. |
| 102 size_t remaining_recv_slots_; | 116 size_t remaining_recv_slots_; |
| 103 | 117 |
| 104 // The queue owns the PendingSendRequest instances. | 118 // The queue owns the PendingSendRequest instances. |
| 105 std::deque<PendingSendRequest*> pending_send_requests_; | 119 std::deque<PendingSendRequest*> pending_send_requests_; |
| 106 // The maximum size of the |pending_send_requests_| queue. | 120 // The maximum size of the |pending_send_requests_| queue. |
| 107 size_t max_pending_send_requests_; | 121 size_t max_pending_send_requests_; |
| 108 | 122 |
| 109 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); | 123 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); |
| 110 }; | 124 }; |
| 111 | 125 |
| 112 } // namespace mojo | 126 } // namespace mojo |
| 113 | 127 |
| 114 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ | 128 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
| OLD | NEW |