cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / mojo / services / network / udp_socket_impl.h
blob3da68b37b4a34cec071738f0fa358a7394f162a6
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_
8 #include <deque>
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "mojo/application/public/cpp/app_lifetime_helper.h"
13 #include "mojo/services/network/public/interfaces/udp_socket.mojom.h"
14 #include "net/base/ip_endpoint.h"
15 #include "net/udp/udp_socket.h"
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
18 namespace net {
19 class IOBuffer;
20 class IOBufferWithSize;
23 namespace mojo {
25 class UDPSocketImpl : public UDPSocket {
26 public:
27 // The lifetime of a new UDPSocketImpl is bound to the connection associated
28 // with |request|.
29 UDPSocketImpl(InterfaceRequest<UDPSocket> request,
30 scoped_ptr<mojo::AppRefCount> app_refcount);
31 ~UDPSocketImpl() override;
33 // UDPSocket implementation.
34 void AllowAddressReuse(
35 const Callback<void(NetworkErrorPtr)>& callback) override;
37 void Bind(NetAddressPtr addr,
38 const Callback<void(NetworkErrorPtr,
39 NetAddressPtr,
40 InterfaceRequest<UDPSocketReceiver>)>& callback)
41 override;
43 void Connect(NetAddressPtr remote_addr,
44 const Callback<void(NetworkErrorPtr,
45 NetAddressPtr,
46 InterfaceRequest<UDPSocketReceiver>)>&
47 callback) override;
49 void SetSendBufferSize(
50 uint32_t size,
51 const Callback<void(NetworkErrorPtr)>& callback) override;
53 void SetReceiveBufferSize(
54 uint32_t size,
55 const Callback<void(NetworkErrorPtr)>& callback) override;
57 void NegotiateMaxPendingSendRequests(
58 uint32_t requested_size,
59 const Callback<void(uint32_t)>& callback) override;
61 void ReceiveMore(uint32_t datagram_number) override;
63 void SendTo(NetAddressPtr dest_addr,
64 Array<uint8_t> data,
65 const Callback<void(NetworkErrorPtr)>& callback) override;
67 private:
68 enum State {
69 NOT_BOUND_OR_CONNECTED,
70 BOUND,
71 CONNECTED
74 struct PendingSendRequest {
75 PendingSendRequest();
76 ~PendingSendRequest();
78 NetAddressPtr addr;
79 Array<uint8_t> data;
80 Callback<void(NetworkErrorPtr)> callback;
83 void DoRecvFrom();
84 void DoSendTo(NetAddressPtr addr,
85 Array<uint8_t> data,
86 const Callback<void(NetworkErrorPtr)>& callback);
88 void OnRecvFromCompleted(int net_result);
89 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback,
90 int net_result);
92 bool IsBoundOrConnected() const {
93 return state_ == BOUND || state_ == CONNECTED;
96 StrongBinding<UDPSocket> binding_;
98 net::UDPSocket socket_;
100 State state_;
102 bool allow_address_reuse_;
104 // Non-null when there is a pending RecvFrom operation on |socket_|.
105 scoped_refptr<net::IOBuffer> recvfrom_buffer_;
106 // Non-null when there is a pending SendTo operation on |socket_|.
107 scoped_refptr<net::IOBufferWithSize> sendto_buffer_;
109 // The address of the pending RecvFrom operation, if any.
110 net::IPEndPoint recvfrom_address_;
112 // The interface which gets data from fulfilled receive requests.
113 UDPSocketReceiverPtr receiver_;
115 // How many more packets the client side expects to receive.
116 size_t remaining_recv_slots_;
118 // The queue owns the PendingSendRequest instances.
119 std::deque<PendingSendRequest*> pending_send_requests_;
120 // The maximum size of the |pending_send_requests_| queue.
121 size_t max_pending_send_requests_;
123 scoped_ptr<mojo::AppRefCount> app_refcount_;
125 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl);
128 } // namespace mojo
130 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_