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" |
| 9 | |
| 10 | namespace openscreen { |
| 11 | namespace platform { |
| 12 | |
| 13 | // Opaque type for the platform to implement. |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 14 | struct UdpSocketPrivate; |
| 15 | using UdpSocketPtr = UdpSocketPrivate*; |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 16 | |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 17 | UdpSocketPtr CreateUdpSocketIPv4(); |
| 18 | UdpSocketPtr CreateUdpSocketIPv6(); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 19 | |
| 20 | // Closes the underlying platform socket and frees any allocated memory. |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 21 | void DestroyUdpSocket(UdpSocketPtr socket); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 22 | |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 23 | bool BindUdpSocket(UdpSocketPtr socket, |
| 24 | const IPEndpoint& endpoint, |
| 25 | int32_t ifindex); |
| 26 | bool JoinUdpMulticastGroup(UdpSocketPtr socket, |
| 27 | const IPAddress& address, |
| 28 | int32_t ifindex); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 29 | |
btolsch | 56aa52a | 2018-09-10 11:40:12 -0700 | [diff] [blame] | 30 | int64_t ReceiveUdp(UdpSocketPtr socket, |
| 31 | void* data, |
| 32 | int64_t length, |
| 33 | IPEndpoint* src, |
| 34 | IPEndpoint* original_destination); |
| 35 | int64_t SendUdp(UdpSocketPtr socket, |
| 36 | const void* data, |
| 37 | int64_t length, |
| 38 | const IPEndpoint& dest); |
btolsch | 9ccfa78 | 2018-07-26 00:16:08 -0700 | [diff] [blame] | 39 | |
| 40 | } // namespace platform |
| 41 | } // namespace openscreen |
| 42 | |
btolsch | a21e8ed | 2018-08-30 15:13:48 -0700 | [diff] [blame] | 43 | #endif // PLATFORM_API_SOCKET_H_ |