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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/network/udp_socket_impl.h
diff --git a/mojo/services/network/udp_socket_impl.h b/mojo/services/network/udp_socket_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..e4c4d28d0a877fdf55a8dc271b2ed18a671b0620
--- /dev/null
+++ b/mojo/services/network/udp_socket_impl.h
@@ -0,0 +1,98 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_
+#define MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_
+
+#include <deque>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "mojo/public/cpp/bindings/interface_impl.h"
+#include "mojo/services/public/interfaces/network/udp_socket.mojom.h"
+#include "net/base/ip_endpoint.h"
+#include "net/udp/udp_server_socket.h"
+
+namespace net {
+class IOBuffer;
+class IOBufferWithSize;
+}
+
+namespace mojo {
+
+class UDPSocketImpl : public InterfaceImpl<UDPSocket> {
+ public:
+ UDPSocketImpl();
+ virtual ~UDPSocketImpl();
+
+ // UDPSocket implementation.
+ virtual void AllowAddressReuse(
+ const Callback<void(NetworkErrorPtr)>& callback) override;
+
+ virtual void Bind(
+ NetAddressPtr addr,
+ const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) override;
+
+ virtual void SetSendBufferSize(
+ uint32_t size,
+ const Callback<void(NetworkErrorPtr)>& callback) override;
+
+ virtual void SetReceiveBufferSize(
+ uint32_t size,
+ const Callback<void(NetworkErrorPtr)>& callback) override;
+
+ virtual void NegotiateMaxPendingSendRequests(
+ uint32_t requested_size,
+ const Callback<void(uint32_t)>& callback) override;
+
+ virtual void ReceiveMore(uint32_t datagram_number) override;
+
+ virtual void SendTo(NetAddressPtr dest_addr,
+ Array<uint8_t> data,
+ const Callback<void(NetworkErrorPtr)>& callback) override;
+
+ private:
+ struct PendingSendRequest {
+ PendingSendRequest();
+ ~PendingSendRequest();
+
+ NetAddressPtr addr;
+ Array<uint8_t> data;
+ Callback<void(NetworkErrorPtr)> callback;
+ };
+
+ void DoRecvFrom();
+ void DoSendTo(NetAddressPtr addr,
+ Array<uint8_t> data,
+ const Callback<void(NetworkErrorPtr)>& callback);
+
+ void OnRecvFromCompleted(int net_result);
+ void OnSendToCompleted(const Callback<void(NetworkErrorPtr)>& callback,
+ int net_result);
+
+ net::UDPServerSocket socket_;
+
+ bool bound_;
+
+ // Non-NULL when there is a pending RecvFrom operation on |socket_|.
+ scoped_refptr<net::IOBuffer> recvfrom_buffer_;
+ // Non-NULL when there is a pending SendTo operation on |socket_|.
+ scoped_refptr<net::IOBufferWithSize> sendto_buffer_;
+
+ net::IPEndPoint recvfrom_address_;
+
+ // How many more packets the client side expects to receive.
+ size_t remaining_recv_slots_;
+
+ // The queue owns the PendingSendRequest instances.
+ std::deque<PendingSendRequest*> pending_send_requests_;
+ // The maximum size of the |pending_send_requests_| queue.
+ size_t max_pending_send_requests_;
+
+ DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl);
+};
+
+} // namespace mojo
+
+#endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_
« 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