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.
5 #ifndef MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_
6 #define MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_
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/network/public/interfaces/udp_socket.mojom.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/udp/udp_server_socket.h"
19 class IOBufferWithSize
;
24 class UDPSocketImpl
: public InterfaceImpl
<UDPSocket
> {
27 ~UDPSocketImpl() override
;
29 // UDPSocket implementation.
30 void AllowAddressReuse(
31 const Callback
<void(NetworkErrorPtr
)>& callback
) override
;
35 const Callback
<void(NetworkErrorPtr
, NetAddressPtr
)>& callback
) override
;
37 void SetSendBufferSize(
39 const Callback
<void(NetworkErrorPtr
)>& callback
) override
;
41 void SetReceiveBufferSize(
43 const Callback
<void(NetworkErrorPtr
)>& callback
) override
;
45 void NegotiateMaxPendingSendRequests(
46 uint32_t requested_size
,
47 const Callback
<void(uint32_t)>& callback
) override
;
49 void ReceiveMore(uint32_t datagram_number
) override
;
51 void SendTo(NetAddressPtr dest_addr
,
53 const Callback
<void(NetworkErrorPtr
)>& callback
) override
;
56 struct PendingSendRequest
{
58 ~PendingSendRequest();
62 Callback
<void(NetworkErrorPtr
)> callback
;
66 void DoSendTo(NetAddressPtr addr
,
68 const Callback
<void(NetworkErrorPtr
)>& callback
);
70 void OnRecvFromCompleted(int net_result
);
71 void OnSendToCompleted(const Callback
<void(NetworkErrorPtr
)>& callback
,
74 net::UDPServerSocket socket_
;
78 // Non-NULL when there is a pending RecvFrom operation on |socket_|.
79 scoped_refptr
<net::IOBuffer
> recvfrom_buffer_
;
80 // Non-NULL when there is a pending SendTo operation on |socket_|.
81 scoped_refptr
<net::IOBufferWithSize
> sendto_buffer_
;
83 net::IPEndPoint recvfrom_address_
;
85 // How many more packets the client side expects to receive.
86 size_t remaining_recv_slots_
;
88 // The queue owns the PendingSendRequest instances.
89 std::deque
<PendingSendRequest
*> pending_send_requests_
;
90 // The maximum size of the |pending_send_requests_| queue.
91 size_t max_pending_send_requests_
;
93 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl
);
98 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_