Chromium Code Reviews| 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..6150797877d9f6fc5e4f5b2fc8d73b7113de9846 |
| --- /dev/null |
| +++ b/mojo/services/network/udp_socket_impl.h |
| @@ -0,0 +1,90 @@ |
| +// 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 <queue> |
| + |
| +#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(); |
| + |
| + 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 AllowAddressReuse( |
| + const Callback<void(NetworkErrorPtr)>& callback) OVERRIDE; |
| + |
| + virtual void Bind( |
| + NetAddressPtr addr, |
| + const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) OVERRIDE; |
| + |
| + virtual void ReceiveMorePackets(uint32_t number) OVERRIDE; |
| + |
| + virtual void SendToAndForget(NetAddressPtr addr, |
| + Array<uint8_t> data) OVERRIDE; |
| + |
| + virtual void SendTo(NetAddressPtr 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_; |
| + |
| + scoped_refptr<net::IOBuffer> recvfrom_buffer_; |
| + scoped_refptr<net::IOBufferWithSize> sendto_buffer_; |
|
brettw
2014/09/29 18:24:26
This seems to be used in a nontrivial way and has
yzshen1
2014/09/29 21:51:12
Done.
|
| + |
| + net::IPEndPoint recvfrom_address_; |
| + |
| + size_t remaining_recv_slots_; |
|
brettw
2014/09/29 18:24:26
This one isn't self-explanatory to me.
yzshen1
2014/09/29 21:51:12
Done.
|
| + |
| + std::queue<PendingSendRequest*> pending_send_requests_; |
|
brettw
2014/09/29 18:24:26
Can you clarify these are owning pointers?
yzshen1
2014/09/29 21:51:12
Done.
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(UDPSocketImpl); |
| +}; |
| + |
| +} // namespace mojo |
| + |
| +#endif // MOJO_SERVICES_NETWORK_UDP_SOCKET_IMPL_H_ |