Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: mojo/services/network/udp_socket_impl.h

Issue 596383002: Mojo UDP API implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@udp_interface
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/services/network/network_service_impl.cc ('k') | mojo/services/network/udp_socket_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <deque>
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 // UDPSocket implementation.
30 virtual void AllowAddressReuse(
31 const Callback<void(NetworkErrorPtr)>& callback) override;
32
33 virtual void Bind(
34 NetAddressPtr addr,
35 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override;
36
37 virtual void SetSendBufferSize(
38 uint32_t size,
39 const Callback<void(NetworkErrorPtr)>& callback) override;
40
41 virtual void SetReceiveBufferSize(
42 uint32_t size,
43 const Callback<void(NetworkErrorPtr)>& callback) override;
44
45 virtual void NegotiateMaxPendingSendRequests(
46 uint32_t requested_size,
47 const Callback<void(uint32_t)>& callback) override;
48
49 virtual void ReceiveMore(uint32_t datagram_number) override;
50
51 virtual void SendTo(NetAddressPtr dest_addr,
52 Array<uint8_t> data,
53 const Callback<void(NetworkErrorPtr)>& callback) override;
54
55 private:
56 struct PendingSendRequest {
57 PendingSendRequest();
58 ~PendingSendRequest();
59
60 NetAddressPtr addr;
61 Array<uint8_t> data;
62 Callback<void(NetworkErrorPtr)> callback;
63 };
64
65 void DoRecvFrom();
66 void DoSendTo(NetAddressPtr addr,
67 Array<uint8_t> data,
68 const Callback<void(NetworkErrorPtr)>& callback);
69
70 void OnRecvFromCompleted(int net_result);
71 void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback,
72 int net_result);
73
74 net::UDPServerSocket socket_;
75
76 bool bound_;
77
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_;
82
83 net::IPEndPoint recvfrom_address_;
84
85 // How many more packets the client side expects to receive.
86 size_t remaining_recv_slots_;
87
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_;
92
93 DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl);
94 };
95
96 } // namespace mojo
97
98 #endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/services/network/network_service_impl.cc ('k') | mojo/services/network/udp_socket_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698