btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 1 | // Copyright 2018 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 PLATFORM_API_SOCKET_H_ |
| 6 | #define PLATFORM_API_SOCKET_H_ |
| 7 | |
| 8 | #include "base/ip_address.h" |
Yuri Wiitala | 82edd20 | 2018-10-31 18:42:58 -0700 | [diff] [blame^] | 9 | #include "platform/api/network_interface.h" |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 10 | |
| 11 | namespace openscreen { |
| 12 | namespace platform { |
| 13 | |
| 14 | // Opaque type for the platform to implement. |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 15 | struct UdpSocketPrivate; |
| 16 | using UdpSocketPtr = UdpSocketPrivate*; |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 17 | |
Yuri Wiitala | 82edd20 | 2018-10-31 18:42:58 -0700 | [diff] [blame^] | 18 | // TODO(miu): These should return std::unique_ptr<>, so that code structure |
| 19 | // auto-scopes the lifetime of the instance (i.e., auto-closing the socket too). |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 20 | UdpSocketPtr CreateUdpSocketIPv4(); |
| 21 | UdpSocketPtr CreateUdpSocketIPv6(); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 22 | |
| 23 | // Closes the underlying platform socket and frees any allocated memory. |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 24 | void DestroyUdpSocket(UdpSocketPtr socket); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 25 | |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 26 | bool BindUdpSocket(UdpSocketPtr socket, |
| 27 | const IPEndpoint& endpoint, |
Yuri Wiitala | 82edd20 | 2018-10-31 18:42:58 -0700 | [diff] [blame^] | 28 | InterfaceIndex ifindex); |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 29 | bool JoinUdpMulticastGroup(UdpSocketPtr socket, |
| 30 | const IPAddress& address, |
Yuri Wiitala | 82edd20 | 2018-10-31 18:42:58 -0700 | [diff] [blame^] | 31 | InterfaceIndex ifindex); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 32 | |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 33 | int64_t ReceiveUdp(UdpSocketPtr socket, |
| 34 | void* data, |
| 35 | int64_t length, |
| 36 | IPEndpoint* src, |
| 37 | IPEndpoint* original_destination); |
| 38 | int64_t SendUdp(UdpSocketPtr socket, |
| 39 | const void* data, |
| 40 | int64_t length, |
| 41 | const IPEndpoint& dest); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 42 | |
| 43 | } // namespace platform |
| 44 | } // namespace openscreen |
| 45 | |
btolsch | a21e8ed | 2018-08-30 15:13:48 -0700 | [diff] [blame] | 46 | #endif // PLATFORM_API_SOCKET_H_ |