OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
| 6 #define MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
| 7 |
| 8 #include <queue> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "mojo/public/cpp/bindings/interface_impl.h" |
| 13 #include "mojo/services/public/interfaces/network/udp_socket.mojom.h" |
| 14 #include "net/base/ip_endpoint.h" |
| 15 #include "net/udp/udp_server_socket.h" |
| 16 |
| 17 namespace net { |
| 18 class IOBuffer; |
| 19 class IOBufferWithSize; |
| 20 } |
| 21 |
| 22 namespace mojo { |
| 23 |
| 24 class UDPSocketImpl : public InterfaceImpl<UDPSocket> { |
| 25 public: |
| 26 UDPSocketImpl(); |
| 27 virtual ~UDPSocketImpl(); |
| 28 |
| 29 virtual void SetSendBufferSize( |
| 30 uint32_t size, |
| 31 const Callback<void(NetworkErrorPtr)>& callback) OVERRIDE; |
| 32 |
| 33 virtual void SetReceiveBufferSize( |
| 34 uint32_t size, |
| 35 const Callback<void(NetworkErrorPtr)>& callback) OVERRIDE; |
| 36 |
| 37 virtual void AllowAddressReuse( |
| 38 const Callback<void(NetworkErrorPtr)>& callback) OVERRIDE; |
| 39 |
| 40 virtual void Bind( |
| 41 NetAddressPtr addr, |
| 42 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) OVERRIDE; |
| 43 |
| 44 virtual void ReceiveMorePackets(uint32_t number) OVERRIDE; |
| 45 |
| 46 virtual void SendToAndForget(NetAddressPtr addr, |
| 47 Array<uint8_t> data) OVERRIDE; |
| 48 |
| 49 virtual void SendTo(NetAddressPtr addr, |
| 50 Array<uint8_t> data, |
| 51 const Callback<void(NetworkErrorPtr)>& callback) OVERRIDE; |
| 52 |
| 53 private: |
| 54 struct PendingSendRequest { |
| 55 PendingSendRequest(); |
| 56 ~PendingSendRequest(); |
| 57 |
| 58 NetAddressPtr addr; |
| 59 Array<uint8_t> data; |
| 60 Callback<void(NetworkErrorPtr)> callback; |
| 61 }; |
| 62 |
| 63 void DoRecvFrom(); |
| 64 void DoSendTo(NetAddressPtr addr, |
| 65 Array<uint8_t> data, |
| 66 const Callback<void(NetworkErrorPtr)>& callback); |
| 67 |
| 68 void OnRecvFromCompleted(int net_result); |
| 69 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback, |
| 70 int net_result); |
| 71 |
| 72 net::UDPServerSocket socket_; |
| 73 |
| 74 bool bound_; |
| 75 |
| 76 // Non-NULL when there is a pending RecvFrom operation on |socket_|. |
| 77 scoped_refptr<net::IOBuffer> recvfrom_buffer_; |
| 78 // Non-NULL when there is a pending SendTo operation on |socket_|. |
| 79 scoped_refptr<net::IOBufferWithSize> sendto_buffer_; |
| 80 |
| 81 net::IPEndPoint recvfrom_address_; |
| 82 |
| 83 // How many more packets the client side expects to receive. |
| 84 size_t remaining_recv_slots_; |
| 85 |
| 86 // The queue owns the PendingSendRequest instances. |
| 87 std::queue<PendingSendRequest*> pending_send_requests_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); |
| 90 }; |
| 91 |
| 92 } // namespace mojo |
| 93 |
| 94 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |
OLD | NEW |