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. |
| 14 | struct UdpSocketIPv4Private; |
| 15 | using UdpSocketIPv4Ptr = UdpSocketIPv4Private*; |
| 16 | struct UdpSocketIPv6Private; |
| 17 | using UdpSocketIPv6Ptr = UdpSocketIPv6Private*; |
| 18 | |
| 19 | UdpSocketIPv4Ptr CreateUdpSocketIPv4(); |
| 20 | UdpSocketIPv6Ptr CreateUdpSocketIPv6(); |
| 21 | |
| 22 | // Closes the underlying platform socket and frees any allocated memory. |
| 23 | void DestroyUdpSocket(UdpSocketIPv4Ptr socket); |
| 24 | void DestroyUdpSocket(UdpSocketIPv6Ptr socket); |
| 25 | |
| 26 | bool BindUdpSocketIPv4(UdpSocketIPv4Ptr socket, |
| 27 | const IPv4Endpoint& endpoint, |
| 28 | int32_t ifindex); |
| 29 | bool BindUdpSocketIPv6(UdpSocketIPv6Ptr socket, |
| 30 | const IPv6Endpoint& endpoint, |
| 31 | int32_t ifindex); |
| 32 | bool JoinUdpMulticastGroupIPv4(UdpSocketIPv4Ptr socket, |
| 33 | const IPv4Address& address, |
| 34 | int32_t ifindex); |
| 35 | bool JoinUdpMulticastGroupIPv6(UdpSocketIPv6Ptr socket, |
| 36 | const IPv6Address& address, |
| 37 | int32_t ifindex); |
| 38 | |
| 39 | int64_t ReceiveUdpIPv4(UdpSocketIPv4Ptr socket, |
| 40 | void* data, |
| 41 | int64_t length, |
| 42 | IPv4Endpoint* src, |
| 43 | IPv4Endpoint* original_destination); |
| 44 | int64_t ReceiveUdpIPv6(UdpSocketIPv6Ptr socket, |
| 45 | void* data, |
| 46 | int64_t length, |
| 47 | IPv6Endpoint* src, |
| 48 | IPv6Endpoint* original_destination); |
| 49 | int64_t SendUdpIPv4(UdpSocketIPv4Ptr socket, |
| 50 | const void* data, |
| 51 | int64_t length, |
| 52 | const IPv4Endpoint& dest); |
| 53 | int64_t SendUdpIPv6(UdpSocketIPv6Ptr socket, |
| 54 | const void* data, |
| 55 | int64_t length, |
| 56 | const IPv6Endpoint& dest); |
| 57 | |
| 58 | } // namespace platform |
| 59 | } // namespace openscreen |
| 60 | |
| 61 | #endif |