blob: 9f4f5c1e83e42236748ee0d1d5f065093b0355ef [file] [log] [blame]
btolsch9ccfa782018-07-26 00:16:08 -07001// 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 Wiitala82edd202018-10-31 18:42:58 -07009#include "platform/api/network_interface.h"
btolsch9ccfa782018-07-26 00:16:08 -070010
11namespace openscreen {
12namespace platform {
13
14// Opaque type for the platform to implement.
btolsch56aa52a2018-09-10 11:40:12 -070015struct UdpSocketPrivate;
16using UdpSocketPtr = UdpSocketPrivate*;
btolsch9ccfa782018-07-26 00:16:08 -070017
Yuri Wiitala82edd202018-10-31 18:42:58 -070018// 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).
btolsch56aa52a2018-09-10 11:40:12 -070020UdpSocketPtr CreateUdpSocketIPv4();
21UdpSocketPtr CreateUdpSocketIPv6();
btolsch9ccfa782018-07-26 00:16:08 -070022
23// Closes the underlying platform socket and frees any allocated memory.
btolsch56aa52a2018-09-10 11:40:12 -070024void DestroyUdpSocket(UdpSocketPtr socket);
btolsch9ccfa782018-07-26 00:16:08 -070025
btolsch56aa52a2018-09-10 11:40:12 -070026bool BindUdpSocket(UdpSocketPtr socket,
27 const IPEndpoint& endpoint,
Yuri Wiitala82edd202018-10-31 18:42:58 -070028 InterfaceIndex ifindex);
btolsch56aa52a2018-09-10 11:40:12 -070029bool JoinUdpMulticastGroup(UdpSocketPtr socket,
30 const IPAddress& address,
Yuri Wiitala82edd202018-10-31 18:42:58 -070031 InterfaceIndex ifindex);
btolsch9ccfa782018-07-26 00:16:08 -070032
btolsch56aa52a2018-09-10 11:40:12 -070033int64_t ReceiveUdp(UdpSocketPtr socket,
34 void* data,
35 int64_t length,
36 IPEndpoint* src,
37 IPEndpoint* original_destination);
38int64_t SendUdp(UdpSocketPtr socket,
39 const void* data,
40 int64_t length,
41 const IPEndpoint& dest);
btolsch9ccfa782018-07-26 00:16:08 -070042
43} // namespace platform
44} // namespace openscreen
45
btolscha21e8ed2018-08-30 15:13:48 -070046#endif // PLATFORM_API_SOCKET_H_