From 96291cc3789462c4c81773c4bc897eba50c51d5d Mon Sep 17 00:00:00 2001 From: Dhaval Gandhi Date: Fri, 27 Sep 2024 10:20:10 -0700 Subject: [PATCH 1/5] Create 25.LTS.10.md (#4162) Release notes for the 25.LTS.10 b/293645066 --- cobalt/site/docs/releases/25.LTS.10.md | 124 +++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 cobalt/site/docs/releases/25.LTS.10.md diff --git a/cobalt/site/docs/releases/25.LTS.10.md b/cobalt/site/docs/releases/25.LTS.10.md new file mode 100644 index 000000000000..f3b17e2efaef --- /dev/null +++ b/cobalt/site/docs/releases/25.LTS.10.md @@ -0,0 +1,124 @@ +Project: /youtube/cobalt/_project.yaml +Book: /youtube/cobalt/_book.yaml + +## Cobalt 25.LTS.10 Stable Release + +The Cobalt team is thrilled to announce the stable release of **Cobalt 25 LTS +([25.lts.10.1034827](https://github.com/youtube/cobalt/tree/25.lts.10))** + +The Evergreen binaries are available on GitHub +([5.10.2](https://github.com/youtube/cobalt/releases/tag/25.lts.10)) + +Cobalt 25 LTS includes **Starboard API version 16** for porters and this stable +release version supports all features that are required for **2025 YouTube +Certification**. The code is available at Cobalt open source +**[25.lts.10](https://github.com/youtube/cobalt/tree/25.lts.10)** branch. +(Read +[branching](https://github.com/youtube/cobalt/blob/25.lts.10/cobalt/site/docs/gen/cobalt/doc/branching.md) +and +[versioning](https://github.com/youtube/cobalt/blob/25.lts.10/cobalt/site/docs/gen/cobalt/doc/versioning.md) +documents for more information) + +There are newly implemented features, improvements, and simplified code. We have +outlined the changelist with a brief description of **Cobalt 25 LTS** and +**Starboard 16** changes. + +### Cobalt Changes + +(see[ +cobalt/CHANGELOG.md](https://github.com/youtube/cobalt/blob/25.lts.10/cobalt/CHANGELOG.md) +for more information) + +#### New Features / Support + +* **Chromium M114 Update:** Upgraded most Chromium components to align with + the M114 milestone release - including syncing the build environment and + compilers. +* **HTTP/3 with IETF QUIC:** Integrated HTTP/3 with IETF standard QUIC for + enhanced video playback performance in challenging network conditions. +* **Immersive Audio Model and Formats (IAMF):** Added support for IAMF audio. +* **Android U Support:** Extended compatibility to Android U + +#### Updates / Improvements + +* **Embedded ICU Data:** Linked ICU data directly into the Cobalt binary, + reducing storage (via binary compression) and simplifying updates. +* **Logging and Telemetry Enhancements:** Improved logging and telemetry for + update reliability and crash reporting. +* **Critical Stability fixes** : Bug fixes and stability + [improvements](https://github.com/youtube/cobalt/compare/25.lts.1...25.lts.10). + +#### Evergreen + +* **LZ4 Compressed Binaries:** Made LZ4 compressed binaries the default + distribution format. +* **Evergreen-Full on AOSP:** Enabled Evergreen-Full support on AOSP (Android + Open Source). + +### Starboard Changes + +(see +[starboard/CHANGELOG.md](https://github.com/youtube/cobalt/blob/25.lts.10/starboard/CHANGELOG.md) +for more information) + +#### New Features / Support + +* **POSIX API Adoption:** Adopted POSIX APIs (see [migration + guide](https://github.com/youtube/cobalt/blob/25.lts.10/starboard/doc/starboard_16_posix.md) + for details), reducing the total number of Starboard interface functions to + 191 (vs 274 in Starboard 15). +* **Partial Audio Frame Support:** Introduced a new configuration constant + (kHasPartialAudioFramesSupport) for partial audio frames. + +#### Updates / Improvements + +* **pthread Migration:** Migrated various components (e.g.,` + SbConditionVariable`, `SbOnce`, `SbThreadLocalKey`, etc) to pthread. +* **Memory and File System Migration:** Migrated memory allocation functions + (`SbMemoryAllocate`, `SbMemoryMap` and others) to `malloc`, `mmap` and file + system functions (`SbDirectoryOpen`, `SbDirectoryClose` and others) to + equivalent `opendir`, `closedir`. +* **Socket API Migration:** Migrated `SbSocket` to socket APIs. +* **Starboard Extensions : `Accessibility`** and `onScreenKeyboard` Starboard + APIs are converted to Starboard Extensions (available in` + starboard/extension/accessibility.h `and + `starboard/extension/on_screen_keyboard.h` respectively). +* **Build Standard Upgrade:** Upgraded the C build standard to C11. + * Removed `SB_C_NOINLINE`. + * Deprecated `SB_C_INLINE` and removed config for `SB_C_FORCE_INLINE`. + * Removed configs for `SB_EXPORT_PLATFORM` and `SB_IMPORT_PLATFORM`. +* **Configuration Changes:** + * Changed `MAP_EXECUTABLE_MEMORY` from build-time to runtime config + (`kSbCanMapExecutableMemory`). +* **Additional Migrations:** Migrated `SbDirectoryCanOpen`, `SbFileExists`, + and `SbFileGetPathInfo` to `start` , and `SbFileOpen`, `SbFileClose` to + `open`, `close`. + +#### Deprecations + +* **Deprecated Evergreen-x86 ABI:** The x86 platform configurations, builds + and ABI are no longer supported for Evergreen. +* **OnScreenKeyboard:** Deprecated OnScreenKeyboard. +* **Unused Configurations:** Deprecated various unused configurations (e.g., + `B_HAS_GLES2`, `SB_HAS_NV12_TEXTURE_SUPPORT`, `VIRTUAL_REALITY`, + `DeployPathPatterns`, `SPEECH_SYNTHESIS`, `FILESYSTEM_ZERO_FILEINFO_TIME`, + `SB_HAS_PIPE`). +* **Audio and Media:** + * Deprecated SB_HAS_QUIRK(SUPPORT_INT16_AUDIO_SAMPLES). + * Deprecated `SbMediaGetBufferAlignment`, `SbMediaGetBufferPadding` and + `SbMediaGetBufferStorageType`. + * Deprecated `SbMediaIsBufferUsingMemoryPool`, and memory pool is always + used. (`SbMediaIsBufferUsingMemoryPool` is required to be true) +* **Starboard Hash Configs:** Deprecated Starboard hash configs. + +### 2025 YouTube Certification + +Remember to use "_25.lts.10_" for the 2025 YouTube certification and for your +product release. Cobalt Known Issues with Status, Fixes, and Mitigations can be +found in the [YouTube Partner +Portal](https://developers.google.com/youtube/devices/living-room/support/cobalt-known-issues). + +### Contact Points + +Contact our [support channels](https://cobalt.dev/communication.html) if +you have any problems, questions, or feedback. From 46be2002210250d16270f1eb6995cf30b789226f Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Fri, 27 Sep 2024 10:26:42 -0700 Subject: [PATCH 2/5] remove MSC_VER from starboard (#4129) b/362374622 --- starboard/common/optional.h | 5 ++-- starboard/configuration.h | 2 -- starboard/elf_loader/exported_symbols.cc | 9 -------- ...starboard_layer_posix_stat_abi_wrappers.cc | 10 +------- starboard/shared/testing/no_inline.h | 2 -- starboard/types.h | 23 ++++++------------- 6 files changed, 10 insertions(+), 41 deletions(-) diff --git a/starboard/common/optional.h b/starboard/common/optional.h index b7cd608eac44..aeb1cf8d4fc1 100644 --- a/starboard/common/optional.h +++ b/starboard/common/optional.h @@ -184,8 +184,7 @@ class optional { // Overloaded conversion to bool operator for determining whether the optional // is engaged or not. It returns true if the optional is engaged, and false // otherwise. -#if (defined(_MSC_VER) && (_MSC_VER < 1800)) || \ - (defined(__GNUC__) && \ +#if (defined(__GNUC__) && \ (__GNUC__ < 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ < 5)))) // MSVC 2012 does not support explicit cast operators. // http://blogs.msdn.com/b/vcblog/archive/2011/09/12/10209291.aspx @@ -199,7 +198,7 @@ class optional { // == and != are already overloaded for optional, this leaves null tests, // which we use for boolean testing. class PrivateSafeBoolIdiomFakeMemberType; - typedef PrivateSafeBoolIdiomFakeMemberType optional::*SafeBoolIdiomType; + typedef PrivateSafeBoolIdiomFakeMemberType optional::* SafeBoolIdiomType; public: operator const SafeBoolIdiomType() const { diff --git a/starboard/configuration.h b/starboard/configuration.h index 7a3711f0a157..b38c94112604 100644 --- a/starboard/configuration.h +++ b/starboard/configuration.h @@ -45,8 +45,6 @@ #if defined(__GNUC__) #define SB_IS_COMPILER_GCC 1 -#elif defined(_MSC_VER) -#define SB_IS_COMPILER_MSVC 1 #endif // --- Common Helper Macros -------------------------------------------------- diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index 33ecbf6ebac6..bcb28b1b4059 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -387,16 +387,7 @@ ExportedSymbols::ExportedSymbols() { map_["getifaddrs"] = reinterpret_cast(&__abi_wrap_getifaddrs); map_["setsockopt"] = reinterpret_cast(&__abi_wrap_setsockopt); -#if defined(_MSC_VER) - // MSVC provides a template with the same name. - // The cast helps the compiler to pick the correct C function pointer to be - // used. - REGISTER_SYMBOL( - static_cast(vswprintf)); -#else REGISTER_SYMBOL(vswprintf); -#endif // defined(_MSC_VER) } // NOLINT diff --git a/starboard/shared/modular/starboard_layer_posix_stat_abi_wrappers.cc b/starboard/shared/modular/starboard_layer_posix_stat_abi_wrappers.cc index 4f1602662904..c91e9116d29e 100644 --- a/starboard/shared/modular/starboard_layer_posix_stat_abi_wrappers.cc +++ b/starboard/shared/modular/starboard_layer_posix_stat_abi_wrappers.cc @@ -23,21 +23,13 @@ int stat_helper(int retval, musl_info->st_size = stat_info->st_size; musl_info->st_mode = stat_info->st_mode; -#if defined(_MSC_VER) - musl_info->st_atim.tv_sec = stat_info->st_atime; - musl_info->st_atim.tv_nsec = 0; - musl_info->st_mtim.tv_sec = stat_info->st_mtime; - musl_info->st_mtim.tv_nsec = 0; - musl_info->st_ctim.tv_sec = stat_info->st_ctime; - musl_info->st_ctim.tv_nsec = 0; -#else musl_info->st_atim.tv_sec = stat_info->st_atim.tv_sec; musl_info->st_atim.tv_nsec = stat_info->st_atim.tv_nsec; musl_info->st_mtim.tv_sec = stat_info->st_mtim.tv_sec; musl_info->st_mtim.tv_nsec = stat_info->st_mtim.tv_nsec; musl_info->st_ctim.tv_sec = stat_info->st_ctim.tv_sec; musl_info->st_ctim.tv_nsec = stat_info->st_ctim.tv_nsec; -#endif + return retval; } diff --git a/starboard/shared/testing/no_inline.h b/starboard/shared/testing/no_inline.h index 33ebc1f6a1fa..2113bbc3c49b 100644 --- a/starboard/shared/testing/no_inline.h +++ b/starboard/shared/testing/no_inline.h @@ -16,8 +16,6 @@ #define STARBOARD_SHARED_TESTING_NO_INLINE_H_ #if defined(__GNUC__) #define SB_TEST_FORCE_NO_INLINE __attribute__((noinline)) -#elif defined(_MSC_VER) -#define SB_TEST_FORCE_NO_INLINE __declspec(noinline) #else #error "Your compiler is not supported" #endif diff --git a/starboard/types.h b/starboard/types.h index 68c5a5ebb3cb..0d36dd378d80 100644 --- a/starboard/types.h +++ b/starboard/types.h @@ -27,13 +27,13 @@ // The C library used must provide these headers to be standard conforming. -#include -#include -#include -#include -#include -#include -#include +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT #if SB_HAS(SYS_TYPES_H) #include @@ -55,11 +55,6 @@ typedef int64_t ssize_t; #endif #endif // !SB_HAS(SSIZE_T) -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable : 4310) // Cast truncates constant value. -#endif - // Simulate needed portions of limits.h for platforms that don't provide it. static const int8_t kSbInt8Min = ((int8_t)0x80); @@ -78,10 +73,6 @@ static const int64_t kSbInt64Min = ((int64_t)SB_INT64_C(0x8000000000000000)); static const int64_t kSbInt64Max = ((int64_t)SB_INT64_C(0x7FFFFFFFFFFFFFFF)); static const uint64_t kSbUInt64Max = ((uint64_t)SB_INT64_C(0xFFFFFFFFFFFFFFFF)); -#if defined(_MSC_VER) -#pragma warning(pop) -#endif - // A value that represents an int that is probably invalid. #define kSbInvalidInt kSbInt32Min From 4a475f34ffdc8d8925e11b1a99de5e9158f30c81 Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Mon, 30 Sep 2024 10:42:57 -0700 Subject: [PATCH 3/5] Clean up socket.h header (#4158) b/369182833 --- starboard/android/shared/BUILD.gn | 11 - starboard/common/socket.cc | 36 -- starboard/common/socket.h | 1 - starboard/elf_loader/exported_symbols.cc | 11 - starboard/linux/shared/BUILD.gn | 11 - starboard/nplb/BUILD.gn | 13 - starboard/nplb/socket_accept_test.cc | 86 ---- starboard/nplb/socket_bind_test.cc | 139 ------ starboard/nplb/socket_connect_test.cc | 56 --- starboard/nplb/socket_create_test.cc | 99 ---- .../nplb/socket_get_interface_address_test.cc | 5 + .../nplb/socket_get_local_address_test.cc | 6 + starboard/nplb/socket_helpers.cc | 437 ------------------ starboard/nplb/socket_helpers.h | 98 ---- .../nplb/socket_is_connected_and_idle_test.cc | 6 + starboard/nplb/socket_is_connected_test.cc | 3 + .../nplb/socket_join_multicast_group_test.cc | 127 ----- starboard/nplb/socket_listen_test.cc | 61 --- starboard/nplb/socket_receive_from_test.cc | 2 + starboard/nplb/socket_resolve_test.cc | 121 ----- starboard/nplb/socket_send_to_test.cc | 203 -------- starboard/nplb/socket_set_options_test.cc | 75 --- starboard/nplb/socket_waiter_add_test.cc | 217 --------- starboard/nplb/socket_waiter_remove_test.cc | 105 ----- starboard/nplb/socket_waiter_wait_test.cc | 273 ----------- .../nplb/socket_waiter_wait_timed_test.cc | 144 ------ starboard/nplb/socket_wrapper_test.cc | 2 + starboard/raspi/shared/BUILD.gn | 11 - .../shared/libevent/socket_waiter_internal.cc | 90 ---- .../shared/posix/socket_free_resolution.cc | 29 -- starboard/shared/posix/socket_is_connected.cc | 41 -- .../posix/socket_is_connected_and_idle.cc | 42 -- .../posix/socket_join_multicast_group.cc | 56 --- starboard/shared/posix/socket_resolve.cc | 86 ---- .../shared/posix/socket_set_broadcast.cc | 26 -- .../posix/socket_set_receive_buffer_size.cc | 26 -- .../posix/socket_set_send_buffer_size.cc | 26 -- .../shared/posix/socket_set_tcp_keep_alive.cc | 40 -- .../shared/posix/socket_set_tcp_no_delay.cc | 27 -- .../posix/socket_set_tcp_window_scaling.cc | 20 - starboard/shared/starboard/net_args.cc | 162 ------- starboard/shared/starboard/net_args.h | 57 --- .../shared/stub/socket_free_resolution.cc | 17 - starboard/shared/stub/socket_is_connected.cc | 19 - .../stub/socket_is_connected_and_idle.cc | 19 - .../stub/socket_join_multicast_group.cc | 20 - starboard/shared/stub/socket_resolve.cc | 19 - starboard/shared/stub/socket_set_broadcast.cc | 19 - .../stub/socket_set_receive_buffer_size.cc | 19 - .../stub/socket_set_send_buffer_size.cc | 19 - .../shared/stub/socket_set_tcp_keep_alive.cc | 19 - .../shared/stub/socket_set_tcp_no_delay.cc | 19 - .../stub/socket_set_tcp_window_scaling.cc | 19 - starboard/socket.h | 118 ----- starboard/stub/BUILD.gn | 11 - 55 files changed, 24 insertions(+), 3400 deletions(-) delete mode 100644 starboard/nplb/socket_accept_test.cc delete mode 100644 starboard/nplb/socket_bind_test.cc delete mode 100644 starboard/nplb/socket_connect_test.cc delete mode 100644 starboard/nplb/socket_create_test.cc delete mode 100644 starboard/nplb/socket_join_multicast_group_test.cc delete mode 100644 starboard/nplb/socket_listen_test.cc delete mode 100644 starboard/nplb/socket_resolve_test.cc delete mode 100644 starboard/nplb/socket_send_to_test.cc delete mode 100644 starboard/nplb/socket_set_options_test.cc delete mode 100644 starboard/nplb/socket_waiter_add_test.cc delete mode 100644 starboard/nplb/socket_waiter_remove_test.cc delete mode 100644 starboard/nplb/socket_waiter_wait_test.cc delete mode 100644 starboard/nplb/socket_waiter_wait_timed_test.cc delete mode 100644 starboard/shared/posix/socket_free_resolution.cc delete mode 100644 starboard/shared/posix/socket_is_connected.cc delete mode 100644 starboard/shared/posix/socket_is_connected_and_idle.cc delete mode 100644 starboard/shared/posix/socket_join_multicast_group.cc delete mode 100644 starboard/shared/posix/socket_resolve.cc delete mode 100644 starboard/shared/posix/socket_set_broadcast.cc delete mode 100644 starboard/shared/posix/socket_set_receive_buffer_size.cc delete mode 100644 starboard/shared/posix/socket_set_send_buffer_size.cc delete mode 100644 starboard/shared/posix/socket_set_tcp_keep_alive.cc delete mode 100644 starboard/shared/posix/socket_set_tcp_no_delay.cc delete mode 100644 starboard/shared/posix/socket_set_tcp_window_scaling.cc delete mode 100644 starboard/shared/starboard/net_args.cc delete mode 100644 starboard/shared/starboard/net_args.h delete mode 100644 starboard/shared/stub/socket_free_resolution.cc delete mode 100644 starboard/shared/stub/socket_is_connected.cc delete mode 100644 starboard/shared/stub/socket_is_connected_and_idle.cc delete mode 100644 starboard/shared/stub/socket_join_multicast_group.cc delete mode 100644 starboard/shared/stub/socket_resolve.cc delete mode 100644 starboard/shared/stub/socket_set_broadcast.cc delete mode 100644 starboard/shared/stub/socket_set_receive_buffer_size.cc delete mode 100644 starboard/shared/stub/socket_set_send_buffer_size.cc delete mode 100644 starboard/shared/stub/socket_set_tcp_keep_alive.cc delete mode 100644 starboard/shared/stub/socket_set_tcp_no_delay.cc delete mode 100644 starboard/shared/stub/socket_set_tcp_window_scaling.cc diff --git a/starboard/android/shared/BUILD.gn b/starboard/android/shared/BUILD.gn index 52040d577ebf..205740fdf96e 100644 --- a/starboard/android/shared/BUILD.gn +++ b/starboard/android/shared/BUILD.gn @@ -92,25 +92,14 @@ static_library("starboard_platform") { "//starboard/shared/posix/socket_connect.cc", "//starboard/shared/posix/socket_create.cc", "//starboard/shared/posix/socket_destroy.cc", - "//starboard/shared/posix/socket_free_resolution.cc", "//starboard/shared/posix/socket_get_last_error.cc", "//starboard/shared/posix/socket_get_local_address.cc", "//starboard/shared/posix/socket_internal.cc", - "//starboard/shared/posix/socket_is_connected.cc", - "//starboard/shared/posix/socket_is_connected_and_idle.cc", "//starboard/shared/posix/socket_is_ipv6_supported.cc", - "//starboard/shared/posix/socket_join_multicast_group.cc", "//starboard/shared/posix/socket_listen.cc", "//starboard/shared/posix/socket_receive_from.cc", - "//starboard/shared/posix/socket_resolve.cc", "//starboard/shared/posix/socket_send_to.cc", - "//starboard/shared/posix/socket_set_broadcast.cc", - "//starboard/shared/posix/socket_set_receive_buffer_size.cc", "//starboard/shared/posix/socket_set_reuse_address.cc", - "//starboard/shared/posix/socket_set_send_buffer_size.cc", - "//starboard/shared/posix/socket_set_tcp_keep_alive.cc", - "//starboard/shared/posix/socket_set_tcp_no_delay.cc", - "//starboard/shared/posix/socket_set_tcp_window_scaling.cc", "//starboard/shared/posix/storage_write_record.cc", "//starboard/shared/posix/system_break_into_debugger.cc", "//starboard/shared/posix/system_clear_last_error.cc", diff --git a/starboard/common/socket.cc b/starboard/common/socket.cc index 0e4c056c8fab..079e52de75a2 100644 --- a/starboard/common/socket.cc +++ b/starboard/common/socket.cc @@ -92,14 +92,6 @@ Socket* Socket::Accept() { return NULL; } -bool Socket::IsConnected() { - return SbSocketIsConnected(socket_); -} - -bool Socket::IsConnectedAndIdle() { - return SbSocketIsConnectedAndIdle(socket_); -} - bool Socket::IsPending() { return GetLastError() == kSbSocketPending; } @@ -128,38 +120,10 @@ bool Socket::GetLocalAddress(SbSocketAddress* out_address) { return SbSocketGetLocalAddress(socket_, out_address); } -bool Socket::SetBroadcast(bool value) { - return SbSocketSetBroadcast(socket_, value); -} - bool Socket::SetReuseAddress(bool value) { return SbSocketSetReuseAddress(socket_, value); } -bool Socket::SetReceiveBufferSize(int32_t size) { - return SbSocketSetReceiveBufferSize(socket_, size); -} - -bool Socket::SetSendBufferSize(int32_t size) { - return SbSocketSetSendBufferSize(socket_, size); -} - -bool Socket::SetTcpKeepAlive(bool value, int64_t period) { - return SbSocketSetTcpKeepAlive(socket_, value, period); -} - -bool Socket::SetTcpNoDelay(bool value) { - return SbSocketSetTcpNoDelay(socket_, value); -} - -bool Socket::SetTcpWindowScaling(bool value) { - return SbSocketSetTcpWindowScaling(socket_, value); -} - -bool Socket::JoinMulticastGroup(const SbSocketAddress* address) { - return SbSocketJoinMulticastGroup(socket_, address); -} - SbSocket Socket::socket() { return socket_; } diff --git a/starboard/common/socket.h b/starboard/common/socket.h index d02d62318a97..3e877f09aec6 100644 --- a/starboard/common/socket.h +++ b/starboard/common/socket.h @@ -71,7 +71,6 @@ class Socket { bool SetTcpKeepAlive(bool value, int64_t period); // period in microseconds. bool SetTcpNoDelay(bool value); bool SetTcpWindowScaling(bool value); - bool JoinMulticastGroup(const SbSocketAddress* address); SbSocket socket(); diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index bcb28b1b4059..9293c42fe269 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -153,25 +153,14 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(SbSocketConnect); REGISTER_SYMBOL(SbSocketCreate); REGISTER_SYMBOL(SbSocketDestroy); - REGISTER_SYMBOL(SbSocketFreeResolution); REGISTER_SYMBOL(SbSocketGetInterfaceAddress); REGISTER_SYMBOL(SbSocketGetLastError); REGISTER_SYMBOL(SbSocketGetLocalAddress); - REGISTER_SYMBOL(SbSocketIsConnected); - REGISTER_SYMBOL(SbSocketIsConnectedAndIdle); REGISTER_SYMBOL(SbSocketIsIpv6Supported); - REGISTER_SYMBOL(SbSocketJoinMulticastGroup); REGISTER_SYMBOL(SbSocketListen); REGISTER_SYMBOL(SbSocketReceiveFrom); - REGISTER_SYMBOL(SbSocketResolve); REGISTER_SYMBOL(SbSocketSendTo); - REGISTER_SYMBOL(SbSocketSetBroadcast); - REGISTER_SYMBOL(SbSocketSetReceiveBufferSize); REGISTER_SYMBOL(SbSocketSetReuseAddress); - REGISTER_SYMBOL(SbSocketSetSendBufferSize); - REGISTER_SYMBOL(SbSocketSetTcpKeepAlive); - REGISTER_SYMBOL(SbSocketSetTcpNoDelay); - REGISTER_SYMBOL(SbSocketSetTcpWindowScaling); REGISTER_SYMBOL(SbSocketWaiterAdd); REGISTER_SYMBOL(SbSocketWaiterCreate); REGISTER_SYMBOL(SbSocketWaiterDestroy); diff --git a/starboard/linux/shared/BUILD.gn b/starboard/linux/shared/BUILD.gn index c39d975fdd66..e4d7b856f9fb 100644 --- a/starboard/linux/shared/BUILD.gn +++ b/starboard/linux/shared/BUILD.gn @@ -162,25 +162,14 @@ static_library("starboard_platform_sources") { "//starboard/shared/posix/socket_connect.cc", "//starboard/shared/posix/socket_create.cc", "//starboard/shared/posix/socket_destroy.cc", - "//starboard/shared/posix/socket_free_resolution.cc", "//starboard/shared/posix/socket_get_last_error.cc", "//starboard/shared/posix/socket_get_local_address.cc", "//starboard/shared/posix/socket_internal.cc", - "//starboard/shared/posix/socket_is_connected.cc", - "//starboard/shared/posix/socket_is_connected_and_idle.cc", "//starboard/shared/posix/socket_is_ipv6_supported.cc", - "//starboard/shared/posix/socket_join_multicast_group.cc", "//starboard/shared/posix/socket_listen.cc", "//starboard/shared/posix/socket_receive_from.cc", - "//starboard/shared/posix/socket_resolve.cc", "//starboard/shared/posix/socket_send_to.cc", - "//starboard/shared/posix/socket_set_broadcast.cc", - "//starboard/shared/posix/socket_set_receive_buffer_size.cc", "//starboard/shared/posix/socket_set_reuse_address.cc", - "//starboard/shared/posix/socket_set_send_buffer_size.cc", - "//starboard/shared/posix/socket_set_tcp_keep_alive.cc", - "//starboard/shared/posix/socket_set_tcp_no_delay.cc", - "//starboard/shared/posix/socket_set_tcp_window_scaling.cc", "//starboard/shared/posix/storage_write_record.cc", "//starboard/shared/posix/system_break_into_debugger.cc", "//starboard/shared/posix/system_clear_last_error.cc", diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index 618d9f1a10b5..1e71aed0dcd1 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -177,11 +177,7 @@ target(gtest_target_type, "nplb") { "random_helpers.cc", "recursive_mutex_test.cc", "semaphore_test.cc", - "socket_accept_test.cc", - "socket_bind_test.cc", "socket_clear_last_error_test.cc", - "socket_connect_test.cc", - "socket_create_test.cc", "socket_destroy_test.cc", "socket_get_interface_address_test.cc", "socket_get_last_error_test.cc", @@ -189,18 +185,9 @@ target(gtest_target_type, "nplb") { "socket_helpers.cc", "socket_is_connected_and_idle_test.cc", "socket_is_connected_test.cc", - "socket_join_multicast_group_test.cc", - "socket_listen_test.cc", "socket_receive_from_test.cc", - "socket_resolve_test.cc", - "socket_send_to_test.cc", - "socket_set_options_test.cc", - "socket_waiter_add_test.cc", "socket_waiter_create_test.cc", "socket_waiter_destroy_test.cc", - "socket_waiter_remove_test.cc", - "socket_waiter_wait_test.cc", - "socket_waiter_wait_timed_test.cc", "socket_waiter_wake_up_test.cc", "socket_wrapper_test.cc", "speech_synthesis_basic_test.cc", diff --git a/starboard/nplb/socket_accept_test.cc b/starboard/nplb/socket_accept_test.cc deleted file mode 100644 index 477ccf300cb4..000000000000 --- a/starboard/nplb/socket_accept_test.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// The accept SunnyDay case is tested as a subset of at least one other test -// case, so it is not included redundantly here. - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketAcceptTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -TEST_P(SbSocketAcceptTest, RainyDayNoConnection) { - // Set up a socket to listen. - SbSocket server_socket = - CreateListeningTcpSocket(GetAddressType(), GetPortNumberForTests()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - // Don't create a socket to connect to it. - - // Spin briefly to ensure that it won't accept. - SbSocket accepted_socket = AcceptBySpinning(server_socket, kSocketTimeout); - EXPECT_FALSE(SbSocketIsValid(accepted_socket)) - << "Accepted with no one connecting."; - - SbSocketDestroy(accepted_socket); - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -TEST_P(SbSocketAcceptTest, RainyDayNotBound) { - // Set up a socket, but don't Bind or Listen. - SbSocket server_socket = CreateServerTcpSocket(GetAddressType()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - // Accept should result in an error. - EXPECT_EQ(kSbSocketInvalid, SbSocketAccept(server_socket)); - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketGetLastError(server_socket)); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -TEST_P(SbSocketAcceptTest, RainyDayNotListening) { - // Set up a socket, but don't Bind or Listen. - SbSocket server_socket = - CreateBoundTcpSocket(GetAddressType(), GetPortNumberForTests()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - // Accept should result in an error. - EXPECT_EQ(kSbSocketInvalid, SbSocketAccept(server_socket)); - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketGetLastError(server_socket)); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -TEST_P(SbSocketAcceptTest, RainyDayInvalidSocket) { - EXPECT_EQ(kSbSocketInvalid, SbSocketAccept(kSbSocketInvalid)); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketAcceptTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_bind_test.cc b/starboard/nplb/socket_bind_test.cc deleted file mode 100644 index 6da9caa7bcdc..000000000000 --- a/starboard/nplb/socket_bind_test.cc +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// The basic Sunny Day test is a subset of other Sunny Day tests, so it is not -// repeated here. - -#include - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketBindTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketAddressType GetAddressType() { return GetParam().first; } - SbSocketResolveFilter GetFilterType() { return GetParam().second; } -}; - -class PairSbSocketBindTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketAddressType GetServerAddressType() { return GetParam().first; } - SbSocketAddressType GetClientAddressType() { return GetParam().second; } -}; - -// This is to use NULL in asserts, which otherwise complain about long -// vs. pointer type. -const void* kNull = NULL; - -TEST_P(SbSocketBindTest, RainyDayNullSocket) { - SbSocketAddress address = - GetUnspecifiedAddress(GetAddressType(), GetPortNumberForTests()); - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketBind(kSbSocketInvalid, &address)); -} - -TEST_P(SbSocketBindTest, RainyDayNullAddress) { - SbSocket server_socket = CreateServerTcpSocket(GetAddressType()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - // Binding with a NULL address should fail. - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketBind(server_socket, NULL)); - - // Even though that failed, binding the same socket now with 0.0.0.0:2048 - // should work. - SbSocketAddress address = - GetUnspecifiedAddress(GetAddressType(), GetPortNumberForTests()); - EXPECT_EQ(kSbSocketOk, SbSocketBind(server_socket, &address)); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -TEST_F(SbSocketBindTest, RainyDayNullNull) { - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketBind(kSbSocketInvalid, NULL)); -} - -TEST_P(PairSbSocketBindTest, RainyDayWrongAddressType) { - SbSocket server_socket = CreateServerTcpSocket(GetServerAddressType()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - // Binding with the wrong address type should fail. - SbSocketAddress address = - GetUnspecifiedAddress(GetClientAddressType(), GetPortNumberForTests()); - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketBind(server_socket, &address)); - - // Even though that failed, binding the same socket now with the server - // address type should work. - address = - GetUnspecifiedAddress(GetServerAddressType(), GetPortNumberForTests()); - EXPECT_EQ(kSbSocketOk, SbSocketBind(server_socket, &address)); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -TEST_P(SbSocketBindTest, RainyDayBadInterface) { - SbSocket server_socket = CreateServerTcpSocket(GetAddressType()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - // Binding with an interface that doesn't exist on this device should fail, so - // let's find an address of a well-known public website that we shouldn't be - // able to bind to. - const char* kTestHostName = "www.yahoo.com"; - SbSocketResolution* resolution = - SbSocketResolve(kTestHostName, GetFilterType()); - ASSERT_NE(kNull, resolution); - EXPECT_LT(0, resolution->address_count); - EXPECT_SB_SOCKET_ERROR_IS_ERROR( - SbSocketBind(server_socket, &resolution->addresses[0])); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); - SbSocketFreeResolution(resolution); -} - -TEST_F(SbSocketBindTest, SunnyDayLocalInterface) { - SbSocketAddress address = {0}; - EXPECT_TRUE(SbSocketGetInterfaceAddress(NULL, &address, NULL)); - SbSocket server_socket = CreateServerTcpSocket(address.type); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - EXPECT_EQ(kSbSocketOk, SbSocketBind(server_socket, &address)); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -INSTANTIATE_TEST_CASE_P( - SbSocketAddressTypes, - SbSocketBindTest, - ::testing::Values( - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketResolveFilterIpv4), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketResolveFilterIpv6)), - GetSbSocketAddressTypeFilterPairName); -INSTANTIATE_TEST_CASE_P( - SbSocketAddressTypes, - PairSbSocketBindTest, - ::testing::Values( - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketAddressTypeIpv6), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv4)), - GetSbSocketAddressTypePairName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_connect_test.cc b/starboard/nplb/socket_connect_test.cc deleted file mode 100644 index 6dc6adade599..000000000000 --- a/starboard/nplb/socket_connect_test.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// The basic Sunny Day test is a subset of other Sunny Day tests, so it is not -// repeated here. - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketConnectTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -TEST_P(SbSocketConnectTest, RainyDayNullSocket) { - SbSocketAddress address = GetUnspecifiedAddress(GetAddressType(), 2048); - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketConnect(kSbSocketInvalid, &address)); -} - -TEST_P(SbSocketConnectTest, RainyDayNullAddress) { - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketConnect(socket, NULL)); - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_F(SbSocketConnectTest, RainyDayNullNull) { - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketConnect(kSbSocketInvalid, NULL)); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketConnectTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_create_test.cc b/starboard/nplb/socket_create_test.cc deleted file mode 100644 index 1a12b82563e2..000000000000 --- a/starboard/nplb/socket_create_test.cc +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketCreateTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -class PairSbSocketCreateTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketAddressType GetAddressType() { return GetParam().first; } - SbSocketProtocol GetProtocol() { return GetParam().second; } -}; - -TEST_P(PairSbSocketCreateTest, Create) { - SbSocket socket = SbSocketCreate(GetAddressType(), GetProtocol()); - // It is allowed for a platform not to support IPv6 sockets, but we use this - // test to at least exercise the code path. - if (kSbSocketAddressTypeIpv6 == GetAddressType()) { - if (SbSocketIsValid(socket)) { - EXPECT_TRUE(SbSocketDestroy(socket)); - } - return; - } - if (kSbSocketProtocolUdp == GetProtocol()) { - // It is allowed for a platform not to support UDP sockets, but we use this - // test to at least exercise the code path. - if (SbSocketIsValid(socket)) { - EXPECT_TRUE(SbSocketDestroy(socket)); - } - return; - } - ASSERT_TRUE(SbSocketIsValid(socket)); - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_P(SbSocketCreateTest, ATonOfTcp) { - const int kATon = 4096; - for (int i = 0; i < kATon; ++i) { - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - EXPECT_TRUE(SbSocketDestroy(socket)); - } -} - -TEST_P(SbSocketCreateTest, ManyTcpAtOnce) { - const int kMany = 128; - SbSocket sockets[kMany] = {0}; - for (int i = 0; i < kMany; ++i) { - sockets[i] = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(sockets[i])); - } - - for (int i = 0; i < kMany; ++i) { - EXPECT_TRUE(SbSocketDestroy(sockets[i])); - } -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketCreateTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -INSTANTIATE_TEST_CASE_P( - SbSocketTypes, - PairSbSocketCreateTest, - ::testing::Values( - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketProtocolTcp), - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketProtocolUdp), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketProtocolTcp), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketProtocolUdp)), - GetSbSocketAddressTypeProtocolPairName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_get_interface_address_test.cc b/starboard/nplb/socket_get_interface_address_test.cc index e793fd883548..0176c4a167df 100644 --- a/starboard/nplb/socket_get_interface_address_test.cc +++ b/starboard/nplb/socket_get_interface_address_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/common/socket.h" #include "starboard/nplb/socket_helpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -95,6 +97,7 @@ TEST_P(SbSocketGetInterfaceAddressTest, SunnyDayDestination) { EXPECT_EQ(0, source.port); } +#if SB_API_VERSION < 16 TEST_P(SbSocketGetInterfaceAddressTest, SunnyDaySourceForDestination) { const char kTestHostName[] = "www.example.com"; @@ -136,6 +139,7 @@ TEST_P(SbSocketGetInterfaceAddressTest, SunnyDaySourceForDestination) { SbSocketFreeResolution(resolution); } +#endif TEST_P(SbSocketGetInterfaceAddressTest, SunnyDaySourceNotLoopback) { SbSocketAddress destination = {0}; @@ -182,3 +186,4 @@ INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, } // namespace } // namespace nplb } // namespace starboard +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/socket_get_local_address_test.cc b/starboard/nplb/socket_get_local_address_test.cc index 1ab95db1f325..50c867fbee4b 100644 --- a/starboard/nplb/socket_get_local_address_test.cc +++ b/starboard/nplb/socket_get_local_address_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/common/socket.h" @@ -78,6 +80,7 @@ TEST_P(SbSocketGetLocalAddressTest, SunnyDayBoundUnspecified) { EXPECT_TRUE(SbSocketDestroy(server_socket)); } +#if SB_API_VERSION < 17 TEST_F(SbSocketGetLocalAddressTest, SunnyDayBoundSpecified) { SbSocketAddress interface_address = {0}; EXPECT_TRUE(SbSocketGetInterfaceAddress(NULL, &interface_address, NULL)); @@ -120,6 +123,7 @@ TEST_P(PairSbSocketGetLocalAddressTest, SunnyDayConnected) { EXPECT_TRUE(SbSocketDestroy(trio.client_socket)); EXPECT_TRUE(SbSocketDestroy(trio.listen_socket)); } +#endif // SB_API_VERSION < 17 INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, SbSocketGetLocalAddressTest, @@ -138,3 +142,5 @@ INSTANTIATE_TEST_CASE_P( } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/socket_helpers.cc b/starboard/nplb/socket_helpers.cc index e99e2138964b..603efeab8857 100644 --- a/starboard/nplb/socket_helpers.cc +++ b/starboard/nplb/socket_helpers.cc @@ -68,35 +68,6 @@ int GetPortNumberForTests() { #endif } -bool IsUnspecified(const SbSocketAddress* address) { - // Look at each piece of memory and make sure too many of them aren't zero. - int components = (address->type == kSbSocketAddressTypeIpv4 ? 4 : 16); - int zero_count = 0; - for (int i = 0; i < components; ++i) { - if (address->address[i] == 0) { - ++zero_count; - } - } - return components == zero_count; -} - -bool IsLocalhost(const SbSocketAddress* address) { - if (address->type == kSbSocketAddressTypeIpv4) { - return address->address[0] == 127; - } - - if (address->type == kSbSocketAddressTypeIpv6) { - bool may_be_localhost = true; - for (int i = 0; i < 15; ++i) { - may_be_localhost &= (address->address[i] == 0); - } - - return (may_be_localhost && address->address[15] == 1); - } - - return false; -} - SbSocket CreateServerTcpSocket(SbSocketAddressType address_type) { SbSocket server_socket = SbSocketCreate(address_type, kSbSocketProtocolTcp); if (!SbSocketIsValid(server_socket)) { @@ -113,23 +84,6 @@ SbSocket CreateServerTcpSocket(SbSocketAddressType address_type) { return server_socket; } -std::unique_ptr CreateServerTcpSocketWrapped( - SbSocketAddressType address_type) { - std::unique_ptr server_socket = - std::unique_ptr(new Socket(address_type, kSbSocketProtocolTcp)); - if (!server_socket->IsValid()) { - ADD_FAILURE() << "SbSocketCreate failed"; - return std::unique_ptr(); - } - - if (!server_socket->SetReuseAddress(true)) { - ADD_FAILURE() << "SbSocketSetReuseAddress failed"; - return std::unique_ptr(); - } - - return server_socket; -} - SbSocket CreateBoundTcpSocket(SbSocketAddressType address_type, int port) { SbSocket server_socket = CreateServerTcpSocket(address_type); if (!SbSocketIsValid(server_socket)) { @@ -147,25 +101,6 @@ SbSocket CreateBoundTcpSocket(SbSocketAddressType address_type, int port) { return server_socket; } -std::unique_ptr CreateBoundTcpSocketWrapped( - SbSocketAddressType address_type, - int port) { - std::unique_ptr server_socket = - CreateServerTcpSocketWrapped(address_type); - if (!server_socket) { - return std::unique_ptr(); - } - - SbSocketAddress address = GetUnspecifiedAddress(address_type, port); - SbSocketError result = server_socket->Bind(&address); - if (result != kSbSocketOk) { - ADD_FAILURE() << "SbSocketBind to " << port << " failed: " << result; - return std::unique_ptr(); - } - - return server_socket; -} - SbSocket CreateListeningTcpSocket(SbSocketAddressType address_type, int port) { SbSocket server_socket = CreateBoundTcpSocket(address_type, port); if (!SbSocketIsValid(server_socket)) { @@ -182,378 +117,6 @@ SbSocket CreateListeningTcpSocket(SbSocketAddressType address_type, int port) { return server_socket; } -std::unique_ptr CreateListeningTcpSocketWrapped( - SbSocketAddressType address_type, - int port) { - std::unique_ptr server_socket = - CreateBoundTcpSocketWrapped(address_type, port); - if (!server_socket) { - return std::unique_ptr(); - } - - SbSocketError result = server_socket->Listen(); - if (result != kSbSocketOk) { - ADD_FAILURE() << "SbSocketListen failed: " << result; - return std::unique_ptr(); - } - - return server_socket; -} - -namespace { -SbSocket CreateConnectingTcpSocket(SbSocketAddressType address_type, int port) { - SbSocket client_socket = SbSocketCreate(address_type, kSbSocketProtocolTcp); - if (!SbSocketIsValid(client_socket)) { - ADD_FAILURE() << "SbSocketCreate failed"; - return kSbSocketInvalid; - } - - // Connect to localhost:. - SbSocketAddress address = {}; - bool success = GetLocalhostAddress(address_type, port, &address); - if (!success) { - ADD_FAILURE() << "GetLocalhostAddress failed"; - return kSbSocketInvalid; - } - - // This connect will probably return pending, but we'll assume it will connect - // eventually. - SbSocketError result = SbSocketConnect(client_socket, &address); - if (result != kSbSocketOk && result != kSbSocketPending) { - ADD_FAILURE() << "SbSocketConnect failed: " << result; - SbSocketDestroy(client_socket); - return kSbSocketInvalid; - } - - return client_socket; -} - -std::unique_ptr CreateConnectingTcpSocketWrapped( - SbSocketAddressType address_type, - int port) { - std::unique_ptr client_socket = - std::unique_ptr(new Socket(address_type, kSbSocketProtocolTcp)); - if (!client_socket->IsValid()) { - ADD_FAILURE() << "SbSocketCreate failed"; - return std::unique_ptr(); - } - - // Connect to localhost:. - SbSocketAddress address = {}; - bool success = GetLocalhostAddress(address_type, port, &address); - if (!success) { - ADD_FAILURE() << "GetLocalhostAddress failed"; - return std::unique_ptr(); - } - - // This connect will probably return pending, but we'll assume it will connect - // eventually. - SbSocketError result = client_socket->Connect(&address); - if (result != kSbSocketOk && result != kSbSocketPending) { - ADD_FAILURE() << "SbSocketConnect failed: " << result; - return std::unique_ptr(); - } - - return client_socket; -} -} // namespace - -SbSocket AcceptBySpinning(SbSocket server_socket, int64_t timeout) { - int64_t start = CurrentMonotonicTime(); - while (true) { - SbSocket accepted_socket = SbSocketAccept(server_socket); - if (SbSocketIsValid(accepted_socket)) { - return accepted_socket; - } - - // If we didn't get a socket, it should be pending. - EXPECT_EQ(kSbSocketPending, SbSocketGetLastError(server_socket)); - - // Check if we have passed our timeout. - if (CurrentMonotonicTime() - start >= timeout) { - break; - } - - // Just being polite. - sched_yield(); - } - - return kSbSocketInvalid; -} - -std::unique_ptr AcceptBySpinning(Socket* server_socket, - int64_t timeout) { - int64_t start = CurrentMonotonicTime(); - while (true) { - Socket* accepted_socket = server_socket->Accept(); - if (accepted_socket && accepted_socket->IsValid()) { - return std::unique_ptr(accepted_socket); - } - - // If we didn't get a socket, it should be pending. - EXPECT_TRUE(server_socket->IsPending()); - - // Check if we have passed our timeout. - if (CurrentMonotonicTime() - start >= timeout) { - break; - } - - // Just being polite. - sched_yield(); - } - - return std::unique_ptr(); -} - -bool WriteBySpinning(SbSocket socket, - const char* data, - int data_size, - int64_t timeout) { - int64_t start = CurrentMonotonicTime(); - int total = 0; - while (total < data_size) { - int sent = SbSocketSendTo(socket, data + total, data_size - total, NULL); - if (sent >= 0) { - total += sent; - continue; - } - - if (SbSocketGetLastError(socket) != kSbSocketPending) { - return false; - } - - if (CurrentMonotonicTime() - start >= timeout) { - return false; - } - - sched_yield(); - } - - return true; -} - -bool WriteBySpinning(Socket* socket, - const char* data, - int data_size, - int64_t timeout) { - int64_t start = CurrentMonotonicTime(); - int total = 0; - while (total < data_size) { - int sent = socket->SendTo(data + total, data_size - total, NULL); - if (sent >= 0) { - total += sent; - continue; - } - - if (!socket->IsPending()) { - return false; - } - - if (CurrentMonotonicTime() - start >= timeout) { - return false; - } - - sched_yield(); - } - - return true; -} - -bool ReadBySpinning(SbSocket socket, - char* out_data, - int data_size, - int64_t timeout) { - int64_t start = CurrentMonotonicTime(); - int total = 0; - while (total < data_size) { - int received = - SbSocketReceiveFrom(socket, out_data + total, data_size - total, NULL); - if (received >= 0) { - total += received; - continue; - } - - if (SbSocketGetLastError(socket) != kSbSocketPending) { - return false; - } - - if (CurrentMonotonicTime() - start >= timeout) { - return false; - } - - sched_yield(); - } - - return true; -} - -bool ReadBySpinning(Socket* socket, - char* out_data, - int data_size, - int64_t timeout) { - int64_t start = CurrentMonotonicTime(); - int total = 0; - while (total < data_size) { - int received = - socket->ReceiveFrom(out_data + total, data_size - total, NULL); - if (received >= 0) { - total += received; - continue; - } - - if (!socket->IsPending()) { - return false; - } - - if (CurrentMonotonicTime() - start >= timeout) { - return false; - } - - sched_yield(); - } - - return true; -} - -int Transfer(SbSocket receive_socket, - char* out_data, - SbSocket send_socket, - const char* send_data, - int size) { - int send_total = 0; - int receive_total = 0; - while (receive_total < size) { - if (send_total < size) { - int bytes_sent = SbSocketSendTo(send_socket, send_data + send_total, - size - send_total, NULL); - if (bytes_sent < 0) { - if (SbSocketGetLastError(send_socket) != kSbSocketPending) { - return -1; - } - bytes_sent = 0; - } - - send_total += bytes_sent; - } - - int bytes_received = SbSocketReceiveFrom( - receive_socket, out_data + receive_total, size - receive_total, NULL); - if (bytes_received < 0) { - if (SbSocketGetLastError(receive_socket) != kSbSocketPending) { - return -1; - } - bytes_received = 0; - } - - receive_total += bytes_received; - } - - return size; -} - -int Transfer(Socket* receive_socket, - char* out_data, - Socket* send_socket, - const char* send_data, - int size) { - int send_total = 0; - int receive_total = 0; - while (receive_total < size) { - if (send_total < size) { - int bytes_sent = - send_socket->SendTo(send_data + send_total, size - send_total, NULL); - if (bytes_sent < 0) { - if (!send_socket->IsPending()) { - return -1; - } - bytes_sent = 0; - } - - send_total += bytes_sent; - } - - int bytes_received = receive_socket->ReceiveFrom( - out_data + receive_total, size - receive_total, NULL); - if (bytes_received < 0) { - if (!receive_socket->IsPending()) { - return -1; - } - bytes_received = 0; - } - - receive_total += bytes_received; - } - - return size; -} - -ConnectedTrio CreateAndConnect(SbSocketAddressType server_address_type, - SbSocketAddressType client_address_type, - int port, - int64_t timeout) { - // Verify the listening socket. - SbSocket listen_socket = CreateListeningTcpSocket(server_address_type, port); - if (!SbSocketIsValid(listen_socket)) { - ADD_FAILURE() << "Could not create listen socket."; - return ConnectedTrio(); - } - - // Verify the socket to connect to the listening socket. - SbSocket client_socket = CreateConnectingTcpSocket(client_address_type, port); - if (!SbSocketIsValid(client_socket)) { - ADD_FAILURE() << "Could not create client socket."; - EXPECT_TRUE(SbSocketDestroy(listen_socket)); - return ConnectedTrio(); - } - - // Spin until the accept happens (or we get impatient). - int64_t start = CurrentMonotonicTime(); - SbSocket server_socket = AcceptBySpinning(listen_socket, timeout); - if (!SbSocketIsValid(server_socket)) { - ADD_FAILURE() << "Failed to accept within " << timeout; - EXPECT_TRUE(SbSocketDestroy(listen_socket)); - EXPECT_TRUE(SbSocketDestroy(client_socket)); - return ConnectedTrio(); - } - - return ConnectedTrio(listen_socket, client_socket, server_socket); -} - -std::unique_ptr CreateAndConnectWrapped( - SbSocketAddressType server_address_type, - SbSocketAddressType client_address_type, - int port, - int64_t timeout) { - // Verify the listening socket. - std::unique_ptr listen_socket = - CreateListeningTcpSocketWrapped(server_address_type, port); - if (!listen_socket || !listen_socket->IsValid()) { - ADD_FAILURE() << "Could not create listen socket."; - return std::unique_ptr(); - } - - // Verify the socket to connect to the listening socket. - std::unique_ptr client_socket = - CreateConnectingTcpSocketWrapped(client_address_type, port); - if (!client_socket || !client_socket->IsValid()) { - ADD_FAILURE() << "Could not create client socket."; - return std::unique_ptr(); - } - - // Spin until the accept happens (or we get impatient). - int64_t start = CurrentMonotonicTime(); - std::unique_ptr server_socket = - AcceptBySpinning(listen_socket.get(), timeout); - if (!server_socket || !server_socket->IsValid()) { - ADD_FAILURE() << "Failed to accept within " << timeout; - return std::unique_ptr(); - } - - return std::unique_ptr(new ConnectedTrioWrapped( - std::move(listen_socket), std::move(client_socket), - std::move(server_socket))); -} - int64_t TimedWait(SbSocketWaiter waiter) { int64_t start = CurrentMonotonicTime(); SbSocketWaiterWait(waiter); diff --git a/starboard/nplb/socket_helpers.h b/starboard/nplb/socket_helpers.h index a90228147b26..783cb68e13dc 100644 --- a/starboard/nplb/socket_helpers.h +++ b/starboard/nplb/socket_helpers.h @@ -29,116 +29,18 @@ namespace nplb { const int64_t kSocketTimeout = 200'000; // 200ms -// Returns true if the given address is the unspecified address (all zeros), -// supporting both address types. -bool IsUnspecified(const SbSocketAddress* address); - -// Returns true if the given address is the localhost address, supporting both -// address types. -bool IsLocalhost(const SbSocketAddress* address); - // Returns a valid port number that can be bound to for use in nplb tests. // This will always return the same port number. int GetPortNumberForTests(); // Creates a TCP/IP server socket (sets Reuse Address option). SbSocket CreateServerTcpSocket(SbSocketAddressType address_type); -std::unique_ptr CreateServerTcpSocketWrapped( - SbSocketAddressType address_type); // Creates a TCP/IP socket bound to all interfaces on the given port. SbSocket CreateBoundTcpSocket(SbSocketAddressType address_type, int port); -std::unique_ptr CreateBoundTcpSocketWrapped( - SbSocketAddressType address_type, - int port); // Creates a TCP/IP socket listening on all interfaces on the given port. SbSocket CreateListeningTcpSocket(SbSocketAddressType address_type, int port); -std::unique_ptr CreateListeningTcpSocketWrapped( - SbSocketAddressType address_type, - int port); - -// Tries to accept a new connection from the given listening socket by checking, -// yielding, and retrying for up to timeout. Returns kSbSocketInvalid if no -// socket has been accepted in the given time. -SbSocket AcceptBySpinning(SbSocket listen_socket, int64_t timeout); -std::unique_ptr AcceptBySpinning(Socket* listen_socket, - int64_t timeout); - -// Writes the given data to socket, spinning until success or error. -bool WriteBySpinning(SbSocket socket, - const char* data, - int data_size, - int64_t timeout); -bool WriteBySpinning(Socket* socket, - const char* data, - int data_size, - int64_t timeout); - -// Reads the given amount of data from socket, spinning until success or error. -bool ReadBySpinning(SbSocket socket, - char* out_data, - int data_size, - int64_t timeout); -bool ReadBySpinning(Socket* socket, - char* out_data, - int data_size, - int64_t timeout); - -// Transfers data between the two connected local sockets, spinning until |size| -// has been transferred, or an error occurs. -int Transfer(SbSocket receive_socket, - char* out_data, - SbSocket send_socket, - const char* send_data, - int size); -int Transfer(Socket* receive_socket, - char* out_data, - Socket* send_socket, - const char* send_data, - int size); - -struct ConnectedTrio { - ConnectedTrio() - : listen_socket(kSbSocketInvalid), - client_socket(kSbSocketInvalid), - server_socket(kSbSocketInvalid) {} - ConnectedTrio(SbSocket listen_socket, - SbSocket client_socket, - SbSocket server_socket) - : listen_socket(listen_socket), - client_socket(client_socket), - server_socket(server_socket) {} - SbSocket listen_socket; - SbSocket client_socket; - SbSocket server_socket; -}; - -struct ConnectedTrioWrapped { - ConnectedTrioWrapped() {} - ConnectedTrioWrapped(std::unique_ptr listen_socket, - std::unique_ptr client_socket, - std::unique_ptr server_socket) - : listen_socket(std::move(listen_socket)), - client_socket(std::move(client_socket)), - server_socket(std::move(server_socket)) {} - std::unique_ptr listen_socket; - std::unique_ptr client_socket; - std::unique_ptr server_socket; -}; - -// Creates and returns 3 TCP/IP sockets, a connected client and server, and a -// listener on the given port. If anything fails, adds a failure and returns -// three invalid sockets. -ConnectedTrio CreateAndConnect(SbSocketAddressType server_address_type, - SbSocketAddressType client_address_type, - int port, - int64_t timeout); -std::unique_ptr CreateAndConnectWrapped( - SbSocketAddressType server_address_type, - SbSocketAddressType client_address_type, - int port, - int64_t timeout); // Waits on the given waiter, and returns the elapsed time in microseconds. int64_t TimedWait(SbSocketWaiter waiter); diff --git a/starboard/nplb/socket_is_connected_and_idle_test.cc b/starboard/nplb/socket_is_connected_and_idle_test.cc index a140aa2acd72..cf55a9537717 100644 --- a/starboard/nplb/socket_is_connected_and_idle_test.cc +++ b/starboard/nplb/socket_is_connected_and_idle_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 #include #include "starboard/common/log.h" @@ -53,6 +54,7 @@ TEST_F(SbSocketIsConnectedAndIdleTest, RainyDayInvalidSocket) { EXPECT_FALSE(SbSocketIsConnectedAndIdle(kSbSocketInvalid)); } +#if SB_API_VERSION < 17 TEST_P(PairSbSocketIsConnectedAndIdleTest, SunnyDay) { ConnectedTrio trio = CreateAndConnect(GetServerAddressType(), GetClientAddressType(), @@ -78,6 +80,7 @@ TEST_P(PairSbSocketIsConnectedAndIdleTest, SunnyDay) { EXPECT_TRUE(SbSocketDestroy(trio.client_socket)); EXPECT_TRUE(SbSocketDestroy(trio.listen_socket)); } +#endif // SB_API_VERSION < 17 TEST_P(SbSocketIsConnectedAndIdleTest, SunnyDayNotConnected) { SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); @@ -86,6 +89,7 @@ TEST_P(SbSocketIsConnectedAndIdleTest, SunnyDayNotConnected) { EXPECT_TRUE(SbSocketDestroy(socket)); } +#if SB_API_VERSION < 17 TEST_P(SbSocketIsConnectedAndIdleTest, SunnyDayListeningNotConnected) { SbSocket server_socket = CreateListeningTcpSocket(GetAddressType(), GetPortNumberForTests()); @@ -93,6 +97,7 @@ TEST_P(SbSocketIsConnectedAndIdleTest, SunnyDayListeningNotConnected) { EXPECT_FALSE(SbSocketIsConnectedAndIdle(server_socket)); EXPECT_TRUE(SbSocketDestroy(server_socket)); } +#endif // SB_API_VERSION < 17 INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, SbSocketIsConnectedAndIdleTest, @@ -111,3 +116,4 @@ INSTANTIATE_TEST_CASE_P( } // namespace } // namespace nplb } // namespace starboard +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/socket_is_connected_test.cc b/starboard/nplb/socket_is_connected_test.cc index 550e3709e656..948f1a3cb118 100644 --- a/starboard/nplb/socket_is_connected_test.cc +++ b/starboard/nplb/socket_is_connected_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/common/log.h" @@ -94,3 +96,4 @@ INSTANTIATE_TEST_CASE_P( } // namespace } // namespace nplb } // namespace starboard +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/socket_join_multicast_group_test.cc b/starboard/nplb/socket_join_multicast_group_test.cc deleted file mode 100644 index ca311dea00ef..000000000000 --- a/starboard/nplb/socket_join_multicast_group_test.cc +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "starboard/common/socket.h" -#include "starboard/common/time.h" -#include "starboard/nplb/socket_helpers.h" -#include "starboard/thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -SbSocket CreateMulticastSocket(const SbSocketAddress& address) { - SbSocket socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolUdp); - EXPECT_TRUE(SbSocketIsValid(socket)); - EXPECT_TRUE(SbSocketSetReuseAddress(socket, true)); - - // It will choose a port for me. - SbSocketAddress bind_address = - GetUnspecifiedAddress(kSbSocketAddressTypeIpv4, 0); - EXPECT_EQ(kSbSocketOk, SbSocketBind(socket, &bind_address)); - - EXPECT_TRUE(SbSocketJoinMulticastGroup(socket, &address)); - return socket; -} - -SbSocket CreateSendSocket() { - SbSocket socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolUdp); - EXPECT_TRUE(SbSocketIsValid(socket)); - EXPECT_TRUE(SbSocketSetReuseAddress(socket, true)); - return socket; -} - -TEST(SbSocketJoinMulticastGroupTest, SunnyDay) { - // "224.0.2.0" is an unassigned ad-hoc multicast address. Hopefully no one is - // spamming it on the local network. - // http://www.iana.org/assignments/multicast-addresses/multicast-addresses.xhtml - SbSocketAddress address = GetUnspecifiedAddress(kSbSocketAddressTypeIpv4, 0); - address.address[0] = 224; - address.address[2] = 2; - - SbSocket send_socket = CreateSendSocket(); - SbSocket receive_socket = CreateMulticastSocket(address); - - // Get the bound port. - SbSocketAddress local_address = {0}; - SbSocketGetLocalAddress(receive_socket, &local_address); - address.port = local_address.port; - - const char kBuf[] = "01234567890123456789"; - char buf[SB_ARRAY_SIZE(kBuf)] = {0}; - while (true) { - int sent = - SbSocketSendTo(send_socket, kBuf, SB_ARRAY_SIZE_INT(kBuf), &address); - if (sent < 0) { - SbSocketError error = SbSocketGetLastError(send_socket); - if (error == kSbSocketPending) { - continue; - } - - // Clean up the sockets. - EXPECT_TRUE(SbSocketDestroy(send_socket)); - EXPECT_TRUE(SbSocketDestroy(receive_socket)); - FAIL() << "Failed to send multicast packet: " << error; - return; - } - EXPECT_EQ(SB_ARRAY_SIZE_INT(kBuf), sent); - break; - } - - SbSocketAddress receive_address; - int64_t stop_time = CurrentMonotonicTime() + 1'000'000LL; - while (true) { - // Breaks the case where the test will hang in a loop when - // SbSocketReceiveFrom() always returns kSbSocketPending. - ASSERT_LE(CurrentMonotonicTime(), stop_time) << "Multicast timed out."; - int received = SbSocketReceiveFrom( - receive_socket, buf, SB_ARRAY_SIZE_INT(buf), &receive_address); - if (received < 0 && - SbSocketGetLastError(receive_socket) == kSbSocketPending) { - usleep(1000); - continue; - } - EXPECT_EQ(SB_ARRAY_SIZE_INT(kBuf), received); - break; - } - - for (int i = 0; i < SB_ARRAY_SIZE_INT(kBuf); ++i) { - EXPECT_EQ(kBuf[i], buf[i]) << "position " << i; - } - - EXPECT_TRUE(SbSocketDestroy(send_socket)); - EXPECT_TRUE(SbSocketDestroy(receive_socket)); -} - -TEST(SbSocketJoinMulticastGroupTest, RainyDayInvalidSocket) { - SbSocketAddress address = GetUnspecifiedAddress(kSbSocketAddressTypeIpv4, 0); - EXPECT_FALSE(SbSocketJoinMulticastGroup(kSbSocketInvalid, &address)); -} - -TEST(SbSocketJoinMulticastGroupTest, RainyDayInvalidAddress) { - SbSocket socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolUdp); - ASSERT_TRUE(SbSocketIsValid(socket)); - EXPECT_FALSE(SbSocketJoinMulticastGroup(socket, NULL)); - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_listen_test.cc b/starboard/nplb/socket_listen_test.cc deleted file mode 100644 index 981d5b51ade9..000000000000 --- a/starboard/nplb/socket_listen_test.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// SbSocketListen is Sunny Day tested in several other tests, so those won't be -// included here. - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketListenTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -TEST_F(SbSocketListenTest, RainyDayInvalid) { - EXPECT_SB_SOCKET_ERROR_IS_ERROR(SbSocketListen(kSbSocketInvalid)); -} - -TEST_P(SbSocketListenTest, SunnyDayUnbound) { - SbSocket server_socket = CreateServerTcpSocket(GetAddressType()); - ASSERT_TRUE(SbSocketIsValid(server_socket)); - - EXPECT_EQ(kSbSocketOk, SbSocketListen(server_socket)); - - // Listening on an unbound socket should listen to a system-assigned port on - // all local interfaces. - SbSocketAddress address = {0}; - EXPECT_TRUE(SbSocketGetLocalAddress(server_socket, &address)); - EXPECT_EQ(GetAddressType(), address.type); - EXPECT_NE(0, address.port); - EXPECT_TRUE(IsUnspecified(&address)); - - EXPECT_TRUE(SbSocketDestroy(server_socket)); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketListenTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_receive_from_test.cc b/starboard/nplb/socket_receive_from_test.cc index ce4a43d9146a..e2ba20fd3180 100644 --- a/starboard/nplb/socket_receive_from_test.cc +++ b/starboard/nplb/socket_receive_from_test.cc @@ -68,6 +68,7 @@ int Transfer(SbSocket receive_socket, return size; } +#if SB_API_VERSION < 17 TEST_P(PairSbSocketReceiveFromTest, SunnyDay) { const int kBufSize = 256 * 1024; const int kSockBufSize = kBufSize / 8; @@ -132,6 +133,7 @@ INSTANTIATE_TEST_CASE_P( std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv6), std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv4)), GetSbSocketAddressTypePairName); +#endif // SB_API_VERSION < 17 } // namespace } // namespace nplb diff --git a/starboard/nplb/socket_resolve_test.cc b/starboard/nplb/socket_resolve_test.cc deleted file mode 100644 index b07a20a5e5b2..000000000000 --- a/starboard/nplb/socket_resolve_test.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "starboard/common/log.h" -#include "starboard/common/socket.h" -#include "starboard/common/string.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketResolveTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketResolveFilter GetResolveFilter() { return GetParam().first; } - SbSocketAddressType GetAddressType() { return GetParam().second; } -}; - -// This is to use NULL in asserts, which otherwise complain about long -// vs. pointer type. -const void* kNull = NULL; - -// A random host name to use to test DNS resolution. -const char kTestHostName[] = "www.example.com"; -const char kLocalhost[] = "localhost"; - -#define LOG_ADDRESS(i) "In returned address #" << (i) - -TEST_F(SbSocketResolveTest, SunnyDay) { - SbSocketResolution* resolution = SbSocketResolve(kTestHostName, 0); - ASSERT_NE(kNull, resolution); - EXPECT_LT(0, resolution->address_count); - EXPECT_NE(kNull, resolution->addresses); - for (int i = 0; i < resolution->address_count; ++i) { - const SbSocketAddress& address = resolution->addresses[i]; - EXPECT_TRUE(address.type == kSbSocketAddressTypeIpv4 || - address.type == kSbSocketAddressTypeIpv6) - << LOG_ADDRESS(i); - EXPECT_FALSE(IsUnspecified(&address)) << LOG_ADDRESS(i); - } - - SbSocketFreeResolution(resolution); -} - -TEST_P(SbSocketResolveTest, Localhost) { - SbSocketResolution* resolution = - SbSocketResolve(kLocalhost, GetResolveFilter()); - ASSERT_NE(kNull, resolution); - EXPECT_LT(0, resolution->address_count); - EXPECT_NE(kNull, resolution->addresses); - for (int i = 0; i < resolution->address_count; ++i) { - const SbSocketAddress& address = resolution->addresses[i]; - EXPECT_TRUE(address.type == kSbSocketAddressTypeIpv4 || - address.type == kSbSocketAddressTypeIpv6) - << LOG_ADDRESS(i); - EXPECT_TRUE(IsLocalhost(&address)) << LOG_ADDRESS(i); - EXPECT_FALSE(IsUnspecified(&address)) << LOG_ADDRESS(i); - } - - SbSocketFreeResolution(resolution); -} - -TEST_P(SbSocketResolveTest, SunnyDayFiltered) { - SbSocketResolution* resolution = - SbSocketResolve(kTestHostName, GetResolveFilter()); - ASSERT_NE(kNull, resolution); - EXPECT_LT(0, resolution->address_count); - EXPECT_NE(kNull, resolution->addresses); - for (int i = 0; i < resolution->address_count; ++i) { - const SbSocketAddress& address = resolution->addresses[i]; - EXPECT_EQ(GetAddressType(), address.type) << LOG_ADDRESS(i); - } - SbSocketFreeResolution(resolution); -} - -TEST_F(SbSocketResolveTest, IgnoreExtraBits) { - // Even with this extra bit set, the resolution should come out the same. - SbSocketResolution* resolution1 = SbSocketResolve(kTestHostName, 1 << 14); - SbSocketResolution* resolution2 = SbSocketResolve(kTestHostName, 0); - ASSERT_NE(kNull, resolution1); - ASSERT_NE(kNull, resolution2); - EXPECT_LT(0, resolution2->address_count); - EXPECT_EQ(resolution2->address_count, resolution1->address_count); - EXPECT_NE(kNull, resolution1->addresses); - EXPECT_NE(kNull, resolution2->addresses); - SbSocketFreeResolution(resolution1); - SbSocketFreeResolution(resolution2); -} - -TEST_F(SbSocketResolveTest, RainyDayNullHostname) { - SbSocketResolution* resolution = SbSocketResolve(NULL, 0); - ASSERT_EQ(kNull, resolution); -} - -INSTANTIATE_TEST_CASE_P( - SbSocketAddressTypes, - SbSocketResolveTest, - ::testing::Values( - std::make_pair(kSbSocketResolveFilterIpv4, kSbSocketAddressTypeIpv4), - std::make_pair(kSbSocketResolveFilterIpv6, kSbSocketAddressTypeIpv6)), - GetSbSocketFilterAddressTypePairName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_send_to_test.cc b/starboard/nplb/socket_send_to_test.cc deleted file mode 100644 index 31e89e51ea63..000000000000 --- a/starboard/nplb/socket_send_to_test.cc +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// SendTo is largely tested with ReceiveFrom, so look there for more involved -// tests. - -#include -#include - -#include - -#include "starboard/common/socket.h" -#include "starboard/common/time.h" -#include "starboard/nplb/socket_helpers.h" -#include "starboard/thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class PairSbSocketSendToTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketAddressType GetServerAddressType() { return GetParam().first; } - SbSocketAddressType GetClientAddressType() { return GetParam().second; } -}; - -// Thread entry point to continuously write to a socket that is expected to -// be closed on another thread. -void* SendToServerSocketEntryPoint(void* trio_as_void_ptr) { - pthread_setname_np(pthread_self(), "SendToTest"); - ConnectedTrio* trio = static_cast(trio_as_void_ptr); - // The contents of this buffer are inconsequential. - const size_t kBufSize = 1024; - char* send_buf = new char[kBufSize]; - memset(send_buf, 0, kBufSize); - - // Continue sending to the socket until it fails to send. It's expected that - // SbSocketSendTo will fail when the server socket closes, but the application - // should not terminate. - int64_t start = CurrentMonotonicTime(); - int64_t now = start; - int64_t kTimeout = 1'000'000; // 1 second - int result = 0; - while (result >= 0 && (now - start < kTimeout)) { - result = SbSocketSendTo(trio->server_socket, send_buf, kBufSize, NULL); - now = CurrentMonotonicTime(); - } - - delete[] send_buf; - return NULL; -} - -TEST(SbSocketSendToTest, RainyDayInvalidSocket) { - char buf[16]; - int result = SbSocketSendTo(NULL, buf, sizeof(buf), NULL); - EXPECT_EQ(-1, result); -} - -TEST(SbSocketSendToTest, RainyDayUnconnectedSocket) { - SbSocket socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - char buf[16]; - int result = SbSocketSendTo(socket, buf, sizeof(buf), NULL); - EXPECT_EQ(-1, result); - - EXPECT_SB_SOCKET_ERROR_IN(SbSocketGetLastError(socket), - kSbSocketErrorConnectionReset, - kSbSocketErrorFailed); - - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_P(PairSbSocketSendToTest, RainyDaySendToClosedSocket) { - ConnectedTrio trio = - CreateAndConnect(GetServerAddressType(), GetClientAddressType(), - GetPortNumberForTests(), kSocketTimeout); - EXPECT_NE(trio.client_socket, kSbSocketInvalid); - EXPECT_NE(trio.server_socket, kSbSocketInvalid); - EXPECT_NE(trio.listen_socket, kSbSocketInvalid); - - // We don't need the listen socket, so close it. - EXPECT_TRUE(SbSocketDestroy(trio.listen_socket)); - - // Start a thread to write to the client socket. - pthread_t send_thread = 0; - pthread_create(&send_thread, nullptr, SendToServerSocketEntryPoint, - static_cast(&trio)); - - // Close the client, which should cause writes to the server socket to fail. - EXPECT_TRUE(SbSocketDestroy(trio.client_socket)); - - // Wait for the thread to exit and check the last socket error. - void* thread_result; - EXPECT_EQ(pthread_join(send_thread, &thread_result), 0); - - EXPECT_SB_SOCKET_ERROR_IN(SbSocketGetLastError(trio.server_socket), - kSbSocketErrorConnectionReset, - kSbSocketErrorFailed); - - // Clean up the server socket. - EXPECT_TRUE(SbSocketDestroy(trio.server_socket)); -} - -// Tests the expectation that writing to a socket that is never drained -// will result in that socket becoming full and thus will return a -// kSbSocketPending status, which indicates that it is blocked. -TEST_P(PairSbSocketSendToTest, RainyDaySendToSocketUntilBlocking) { - static const int kChunkSize = 1024; - // 1GB limit for sending data. - static const uint64_t kMaxTransferLimit = 1024 * 1024 * 1024; - - std::unique_ptr trio = - CreateAndConnectWrapped(GetServerAddressType(), GetClientAddressType(), - GetPortNumberForTests(), kSocketTimeout); - ASSERT_TRUE(trio); - // Push data into socket until it dies. - uint64_t num_bytes = 0; - while (num_bytes < kMaxTransferLimit) { - char buff[kChunkSize] = {}; - int result = trio->client_socket->SendTo(buff, sizeof(buff), NULL); - - if (result < 0) { - SbSocketError err = SbSocketGetLastError(trio->client_socket->socket()); - EXPECT_EQ(kSbSocketPending, err); - return; - } - - if (result == 0) { // Connection dropped unexpectedly. - EXPECT_TRUE(false) << "Connection unexpectedly dropped."; - } - - num_bytes += static_cast(result); - } - EXPECT_TRUE(false) << "Max transfer rate reached."; -} - -// Tests the expectation that killing a connection will cause the other -// connected socket to fail to write. For sockets without socket connection -// support this will show up as a generic error. Otherwise this will show -// up as a connection reset error. -TEST_P(PairSbSocketSendToTest, RainyDaySendToSocketConnectionReset) { - static const int kChunkSize = 1024; - - std::unique_ptr trio = - CreateAndConnectWrapped(GetServerAddressType(), GetClientAddressType(), - GetPortNumberForTests(), kSocketTimeout); - ASSERT_TRUE(trio); - - // Kills the server, the client socket will have it's connection reset during - // one of the subsequent writes. - trio->server_socket.reset(); - - // Expect that after some retries the client socket will return that the - // connection will reset. - int kNumRetries = 1000; - for (int i = 0; i < kNumRetries; ++i) { - char buff[kChunkSize] = {}; - usleep(1000); - int result = trio->client_socket->SendTo(buff, sizeof(buff), NULL); - - if (result < 0) { - SbSocketError err = SbSocketGetLastError(trio->client_socket->socket()); - - EXPECT_EQ(kSbSocketErrorConnectionReset, err) - << "Expected connection drop."; - return; - } - - if (result == 0) { - return; // Other way in which the connection was reset. - } - } - ASSERT_TRUE(false) << "Connection was not dropped after " << kNumRetries - << " tries."; -} - -INSTANTIATE_TEST_CASE_P( - SbSocketAddressTypes, - PairSbSocketSendToTest, - ::testing::Values( - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketAddressTypeIpv4), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv6), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv4)), - GetSbSocketAddressTypePairName); -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_set_options_test.cc b/starboard/nplb/socket_set_options_test.cc deleted file mode 100644 index 303a1bbf93ec..000000000000 --- a/starboard/nplb/socket_set_options_test.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketSetOptionsTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -TEST_P(SbSocketSetOptionsTest, TryThemAllTCP) { - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - - EXPECT_TRUE(SbSocketSetReuseAddress(socket, true)); - EXPECT_TRUE(SbSocketSetReceiveBufferSize(socket, 16 * 1024)); - EXPECT_TRUE(SbSocketSetSendBufferSize(socket, 16 * 1024)); - EXPECT_TRUE(SbSocketSetTcpKeepAlive(socket, true, 30'000'000)); - EXPECT_TRUE(SbSocketSetTcpNoDelay(socket, true)); - - // Returns false on unsupported platforms, so we can't check the return value - // generically. - SbSocketSetTcpWindowScaling(socket, true); - - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_P(SbSocketSetOptionsTest, TryThemAllUDP) { - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolUdp); - - EXPECT_TRUE(SbSocketSetBroadcast(socket, true)); - EXPECT_TRUE(SbSocketSetReuseAddress(socket, true)); - EXPECT_TRUE(SbSocketSetReceiveBufferSize(socket, 16 * 1024)); - EXPECT_TRUE(SbSocketSetSendBufferSize(socket, 16 * 1024)); - - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_P(SbSocketSetOptionsTest, RainyDayInvalidSocket) { - EXPECT_FALSE(SbSocketSetReuseAddress(kSbSocketInvalid, true)); - EXPECT_FALSE(SbSocketSetReceiveBufferSize(kSbSocketInvalid, 16 * 1024)); - EXPECT_FALSE(SbSocketSetSendBufferSize(kSbSocketInvalid, 16 * 1024)); - EXPECT_FALSE(SbSocketSetTcpKeepAlive(kSbSocketInvalid, true, 30'000'000)); - EXPECT_FALSE(SbSocketSetTcpNoDelay(kSbSocketInvalid, true)); - EXPECT_FALSE(SbSocketSetTcpWindowScaling(kSbSocketInvalid, true)); -} - -// TODO: Come up with some way to test the effects of these options. - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketSetOptionsTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_waiter_add_test.cc b/starboard/nplb/socket_waiter_add_test.cc deleted file mode 100644 index 15e5c2da9136..000000000000 --- a/starboard/nplb/socket_waiter_add_test.cc +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" -#include "starboard/configuration_constants.h" -#include "starboard/nplb/socket_helpers.h" -#include "starboard/socket_waiter.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketWaiterAddTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -void NoOpSocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* context, - int ready_interests) {} - -TEST_P(SbSocketWaiterAddTest, SunnyDay) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterAddTest, SunnyDayPersistent) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, true)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterAddTest, SunnyDayMany) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - const int kMany = kSbFileMaxOpen; - std::vector sockets(kMany, 0); - for (int i = 0; i < kMany; ++i) { - sockets[i] = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(sockets[i])); - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, sockets[i], NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - } - - for (int i = 0; i < kMany; ++i) { - EXPECT_TRUE(SbSocketDestroy(sockets[i])); - } - - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterAddTest, RainyDayAddToSameWaiter) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - // First add should succeed. - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // Second add should fail. - EXPECT_FALSE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // Remove should succeed. - EXPECT_TRUE(SbSocketWaiterRemove(waiter, socket)); - - // Add after remove should succeed. - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // Second add after remove should fail. - EXPECT_FALSE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterAddTest, RainyDayAddToOtherWaiter) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - SbSocketWaiter waiter2 = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter2)); - - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - // The first add should succeed. - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // Adding to the other waiter should fail. - EXPECT_FALSE(SbSocketWaiterAdd( - waiter2, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // Remove should succeed. - EXPECT_TRUE(SbSocketWaiterRemove(waiter, socket)); - - // Adding to other waiter after removing should succeed. - EXPECT_TRUE(SbSocketWaiterAdd( - waiter2, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // Adding back to first waiter after adding to the other waiter should fail. - EXPECT_FALSE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter2)); -} - -TEST_F(SbSocketWaiterAddTest, RainyDayInvalidSocket) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - EXPECT_FALSE(SbSocketWaiterAdd( - waiter, kSbSocketInvalid, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterAddTest, RainyDayInvalidWaiter) { - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_FALSE(SbSocketWaiterAdd( - kSbSocketWaiterInvalid, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_P(SbSocketWaiterAddTest, RainyDayNoCallback) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_FALSE(SbSocketWaiterAdd( - waiter, socket, NULL, NULL, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterAddTest, RainyDayNoInterest) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_FALSE(SbSocketWaiterAdd(waiter, socket, NULL, - &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestNone, false)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketWaiterAddTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_waiter_remove_test.cc b/starboard/nplb/socket_waiter_remove_test.cc deleted file mode 100644 index 07d5fb47cb9c..000000000000 --- a/starboard/nplb/socket_waiter_remove_test.cc +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "starboard/socket_waiter.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -class SbSocketWaiterRemoveTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -void NoOpSocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* context, - int ready_interests) {} - -TEST_F(SbSocketWaiterRemoveTest, RainyDayInvalidSocket) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - EXPECT_FALSE(SbSocketWaiterRemove(waiter, kSbSocketInvalid)); - - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_F(SbSocketWaiterRemoveTest, SunnyDayAddAndRemove) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - SbSocket socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - EXPECT_TRUE(SbSocketWaiterRemove(waiter, socket)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterRemoveTest, RainyDayInvalidWaiter) { - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_FALSE(SbSocketWaiterRemove(kSbSocketWaiterInvalid, socket)); - - EXPECT_TRUE(SbSocketDestroy(socket)); -} - -TEST_P(SbSocketWaiterRemoveTest, RainyDayNotAdded) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_FALSE(SbSocketWaiterRemove(waiter, socket)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST_P(SbSocketWaiterRemoveTest, RainyDayAlreadyRemoved) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - SbSocket socket = SbSocketCreate(GetAddressType(), kSbSocketProtocolTcp); - ASSERT_TRUE(SbSocketIsValid(socket)); - - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, socket, NULL, &NoOpSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - EXPECT_TRUE(SbSocketWaiterRemove(waiter, socket)); - EXPECT_FALSE(SbSocketWaiterRemove(waiter, socket)); - - EXPECT_TRUE(SbSocketDestroy(socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketWaiterRemoveTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_waiter_wait_test.cc b/starboard/nplb/socket_waiter_wait_test.cc deleted file mode 100644 index 2987eaf16670..000000000000 --- a/starboard/nplb/socket_waiter_wait_test.cc +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "starboard/common/log.h" -#include "starboard/common/semaphore.h" -#include "starboard/common/socket.h" -#include "starboard/nplb/posix_compliance/posix_thread_helpers.h" -#include "starboard/nplb/socket_helpers.h" -#include "starboard/socket_waiter.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SbSocketWaiterWaitTest); -class SbSocketWaiterWaitTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -class PairSbSocketWaiterWaitTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketAddressType GetServerAddressType() { return GetParam().first; } - SbSocketAddressType GetClientAddressType() { return GetParam().second; } -}; - -struct CallbackValues { - int count; - SbSocketWaiter waiter; - SbSocket socket; - void* context; - int ready_interests; -}; - -void TestSocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* context, - int ready_interests) { - CallbackValues* values = reinterpret_cast(context); - if (values) { - ++values->count; - values->waiter = waiter; - values->socket = socket; - values->context = context; - values->ready_interests = ready_interests; - } - SbSocketWaiterWakeUp(waiter); -} - -void FailSocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* context, - int ready_interests) { - ADD_FAILURE() << __FUNCTION__ << " was called."; -} - -TEST_P(PairSbSocketWaiterWaitTest, SunnyDay) { - const int kBufSize = 1024; - - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - ConnectedTrio trio = - CreateAndConnect(GetServerAddressType(), GetClientAddressType(), - GetPortNumberForTests(), kSocketTimeout); - ASSERT_TRUE(SbSocketIsValid(trio.server_socket)); - - // The client socket should be ready to write right away, but not read until - // it gets some data. - CallbackValues values = {0}; - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, trio.client_socket, &values, &TestSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - // This add should do nothing, since it is already registered. Testing here - // because we can see if it fires a write to the proper callback, then it - // properly ignored this second set of parameters. - EXPECT_FALSE(SbSocketWaiterAdd(waiter, trio.client_socket, &values, - &FailSocketWaiterCallback, - kSbSocketWaiterInterestRead, false)); - - WaitShouldNotBlock(waiter); - - EXPECT_EQ(1, values.count); // Check that the callback was called once. - EXPECT_EQ(waiter, values.waiter); - EXPECT_EQ(trio.client_socket, values.socket); - EXPECT_EQ(&values, values.context); - EXPECT_EQ(kSbSocketWaiterInterestWrite, values.ready_interests); - - // Try again to make sure writable sockets are still writable - values.count = 0; - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, trio.client_socket, &values, &TestSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - WaitShouldNotBlock(waiter); - - EXPECT_EQ(1, values.count); // Check that the callback was called once. - EXPECT_EQ(waiter, values.waiter); - EXPECT_EQ(trio.client_socket, values.socket); - EXPECT_EQ(&values, values.context); - EXPECT_EQ(kSbSocketWaiterInterestWrite, values.ready_interests); - - // The client socket should become ready to read after we write some data to - // it. - values.count = 0; - EXPECT_TRUE(SbSocketWaiterAdd(waiter, trio.client_socket, &values, - &TestSocketWaiterCallback, - kSbSocketWaiterInterestRead, false)); - - // Now we can send something to trigger readability. - char* send_buf = new char[kBufSize]; - int bytes_sent = SbSocketSendTo(trio.server_socket, send_buf, kBufSize, NULL); - delete[] send_buf; - EXPECT_LT(0, bytes_sent); - - WaitShouldNotBlock(waiter); - - EXPECT_EQ(1, values.count); - EXPECT_EQ(waiter, values.waiter); - EXPECT_EQ(trio.client_socket, values.socket); - EXPECT_EQ(&values, values.context); - EXPECT_EQ(kSbSocketWaiterInterestRead, values.ready_interests); - - EXPECT_TRUE(SbSocketDestroy(trio.server_socket)); - EXPECT_TRUE(SbSocketDestroy(trio.client_socket)); - EXPECT_TRUE(SbSocketDestroy(trio.listen_socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -struct AlreadyReadyContext { - AlreadyReadyContext() - : waiter(kSbSocketWaiterInvalid), - a_write_result(false), - a_read_result(false), - b_result(false) {} - ~AlreadyReadyContext() { - if (SbSocketIsValid(trio.listen_socket)) { - EXPECT_TRUE(SbSocketDestroy(trio.listen_socket)); - } - if (SbSocketIsValid(trio.server_socket)) { - EXPECT_TRUE(SbSocketDestroy(trio.server_socket)); - } - if (SbSocketIsValid(trio.client_socket)) { - EXPECT_TRUE(SbSocketDestroy(trio.client_socket)); - } - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); - } - - SbSocketWaiter waiter; - ConnectedTrio trio; - Semaphore wrote_a_signal; - bool a_write_result; - bool a_read_result; - Semaphore write_b_signal; - bool b_result; - Semaphore wrote_b_signal; -}; - -const char kAData[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; -const char kBData[] = "bb"; - -void* AlreadyReadyEntryPoint(void* param) { - AlreadyReadyContext* context = reinterpret_cast(param); - - context->a_write_result = - WriteBySpinning(context->trio.server_socket, kAData, - SB_ARRAY_SIZE_INT(kAData), kSocketTimeout); - context->wrote_a_signal.Put(); - - context->write_b_signal.Take(); - context->b_result = - WriteBySpinning(context->trio.server_socket, kBData, - SB_ARRAY_SIZE_INT(kBData), kSocketTimeout); - context->wrote_b_signal.Put(); - return NULL; -} - -void WakeUpSocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* param, - int ready_interests) { - SbSocketWaiterWakeUp(waiter); -} - -void AlreadyReadySocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* param, - int ready_interests) { - AlreadyReadyContext* context = reinterpret_cast(param); - // Read in the A data. - char buffer[SB_ARRAY_SIZE_INT(kAData)]; - context->a_read_result = - ReadBySpinning(context->trio.client_socket, buffer, - SB_ARRAY_SIZE_INT(buffer), kSocketTimeout); - - // Tell the thread to write the B data now. - context->write_b_signal.Put(); - - // Wait until it thinks it has finished. - context->wrote_b_signal.Take(); - - // Now add the second read callback, and hope that it gets called. - EXPECT_TRUE(SbSocketWaiterAdd(waiter, socket, context, - &WakeUpSocketWaiterCallback, - kSbSocketWaiterInterestRead, false)); -} - -// This test ensures that if the socket gets written to while it is not being -// waited on, and inside a callback, it will become ready immediately the next -// time it is waited on. -TEST_P(PairSbSocketWaiterWaitTest, SunnyDayAlreadyReady) { - AlreadyReadyContext context; - context.waiter = SbSocketWaiterCreate(); - ASSERT_TRUE(SbSocketWaiterIsValid(context.waiter)); - - context.trio = - CreateAndConnect(GetServerAddressType(), GetClientAddressType(), - GetPortNumberForTests(), kSocketTimeout); - ASSERT_TRUE(SbSocketIsValid(context.trio.server_socket)); - - EXPECT_TRUE(SbSocketWaiterAdd(context.waiter, context.trio.client_socket, - &context, &AlreadyReadySocketWaiterCallback, - kSbSocketWaiterInterestRead, false)); - - pthread_t thread = 0; - pthread_create(&thread, nullptr, AlreadyReadyEntryPoint, &context); - EXPECT_TRUE(thread != 0); - context.wrote_a_signal.Take(); - - WaitShouldNotBlock(context.waiter); - - EXPECT_EQ(pthread_join(thread, NULL), 0); -} - -TEST_F(SbSocketWaiterWaitTest, RainyDayInvalidWaiter) { - WaitShouldNotBlock(kSbSocketWaiterInvalid); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketWaiterWaitTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); -INSTANTIATE_TEST_CASE_P( - SbSocketAddressTypes, - PairSbSocketWaiterWaitTest, - ::testing::Values( - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketAddressTypeIpv4), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv6), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv4)), - GetSbSocketAddressTypePairName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_waiter_wait_timed_test.cc b/starboard/nplb/socket_waiter_wait_timed_test.cc deleted file mode 100644 index fb459ea326a1..000000000000 --- a/starboard/nplb/socket_waiter_wait_timed_test.cc +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - -#include "starboard/common/log.h" -#include "starboard/common/socket.h" -#include "starboard/nplb/socket_helpers.h" -#include "starboard/socket_waiter.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace starboard { -namespace nplb { -namespace { - -GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SbSocketWaiterWaitTimedTest); -class SbSocketWaiterWaitTimedTest - : public ::testing::TestWithParam { - public: - SbSocketAddressType GetAddressType() { return GetParam(); } -}; - -class PairSbSocketWaiterWaitTimedTest - : public ::testing::TestWithParam< - std::pair > { - public: - SbSocketAddressType GetServerAddressType() { return GetParam().first; } - SbSocketAddressType GetClientAddressType() { return GetParam().second; } -}; - -struct CallbackValues { - int count; - SbSocketWaiter waiter; - SbSocket socket; - void* context; - int ready_interests; -}; - -void TestSocketWaiterCallback(SbSocketWaiter waiter, - SbSocket socket, - void* context, - int ready_interests) { - CallbackValues* values = reinterpret_cast(context); - if (values) { - ++values->count; - values->waiter = waiter; - values->socket = socket; - values->context = context; - values->ready_interests = ready_interests; - } - SbSocketWaiterWakeUp(waiter); -} - -TEST_P(PairSbSocketWaiterWaitTimedTest, SunnyDay) { - const int kBufSize = 1024; - - SbSocketWaiter waiter = SbSocketWaiterCreate(); - EXPECT_TRUE(SbSocketWaiterIsValid(waiter)); - - ConnectedTrio trio = - CreateAndConnect(GetServerAddressType(), GetClientAddressType(), - GetPortNumberForTests(), kSocketTimeout); - ASSERT_TRUE(SbSocketIsValid(trio.server_socket)); - - // The client socket should be ready to write right away, but not read until - // it gets some data. - CallbackValues values = {0}; - EXPECT_TRUE(SbSocketWaiterAdd( - waiter, trio.client_socket, &values, &TestSocketWaiterCallback, - kSbSocketWaiterInterestRead | kSbSocketWaiterInterestWrite, false)); - - TimedWaitShouldNotBlock(waiter, kSocketTimeout); - - // Even though we waited for no time, we should have gotten this callback. - EXPECT_EQ(1, values.count); // Check that the callback was called once. - EXPECT_EQ(waiter, values.waiter); - EXPECT_EQ(trio.client_socket, values.socket); - EXPECT_EQ(&values, values.context); - EXPECT_EQ(kSbSocketWaiterInterestWrite, values.ready_interests); - - // While we haven't written anything, we should block indefinitely, and - // receive no read callbacks. - values.count = 0; - EXPECT_TRUE(SbSocketWaiterAdd(waiter, trio.client_socket, &values, - &TestSocketWaiterCallback, - kSbSocketWaiterInterestRead, false)); - - TimedWaitShouldBlock(waiter, kSocketTimeout); - - EXPECT_EQ(0, values.count); - - // The client socket should become ready to read after we write some data to - // it. - char* send_buf = new char[kBufSize]; - int bytes_sent = SbSocketSendTo(trio.server_socket, send_buf, kBufSize, NULL); - delete[] send_buf; - EXPECT_LT(0, bytes_sent); - - TimedWaitShouldNotBlock(waiter, kSocketTimeout); - - EXPECT_EQ(1, values.count); - EXPECT_EQ(waiter, values.waiter); - EXPECT_EQ(trio.client_socket, values.socket); - EXPECT_EQ(&values, values.context); - EXPECT_EQ(kSbSocketWaiterInterestRead, values.ready_interests); - - EXPECT_TRUE(SbSocketDestroy(trio.server_socket)); - EXPECT_TRUE(SbSocketDestroy(trio.client_socket)); - EXPECT_TRUE(SbSocketDestroy(trio.listen_socket)); - EXPECT_TRUE(SbSocketWaiterDestroy(waiter)); -} - -TEST(SbSocketWaiterWaitTimedTest, RainyDayInvalidWaiter) { - TimedWaitShouldNotBlock(kSbSocketWaiterInvalid, kSocketTimeout); -} - -INSTANTIATE_TEST_CASE_P(SbSocketAddressTypes, - SbSocketWaiterWaitTimedTest, - ::testing::Values(kSbSocketAddressTypeIpv4, - kSbSocketAddressTypeIpv6), - GetSbSocketAddressTypeName); -INSTANTIATE_TEST_CASE_P( - SbSocketAddressTypes, - PairSbSocketWaiterWaitTimedTest, - ::testing::Values( - std::make_pair(kSbSocketAddressTypeIpv4, kSbSocketAddressTypeIpv4), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv6), - std::make_pair(kSbSocketAddressTypeIpv6, kSbSocketAddressTypeIpv4)), - GetSbSocketAddressTypePairName); - -} // namespace -} // namespace nplb -} // namespace starboard diff --git a/starboard/nplb/socket_wrapper_test.cc b/starboard/nplb/socket_wrapper_test.cc index 21750f59666d..295d05bb66f7 100644 --- a/starboard/nplb/socket_wrapper_test.cc +++ b/starboard/nplb/socket_wrapper_test.cc @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 #include @@ -93,3 +94,4 @@ INSTANTIATE_TEST_CASE_P( } // namespace } // namespace nplb } // namespace starboard +#endif // SB_API_VERSION < 17 diff --git a/starboard/raspi/shared/BUILD.gn b/starboard/raspi/shared/BUILD.gn index 6997c48fbb06..3c95568341f5 100644 --- a/starboard/raspi/shared/BUILD.gn +++ b/starboard/raspi/shared/BUILD.gn @@ -120,25 +120,14 @@ static_library("starboard_platform_sources") { "//starboard/shared/posix/socket_connect.cc", "//starboard/shared/posix/socket_create.cc", "//starboard/shared/posix/socket_destroy.cc", - "//starboard/shared/posix/socket_free_resolution.cc", "//starboard/shared/posix/socket_get_last_error.cc", "//starboard/shared/posix/socket_get_local_address.cc", "//starboard/shared/posix/socket_internal.cc", - "//starboard/shared/posix/socket_is_connected.cc", - "//starboard/shared/posix/socket_is_connected_and_idle.cc", "//starboard/shared/posix/socket_is_ipv6_supported.cc", - "//starboard/shared/posix/socket_join_multicast_group.cc", "//starboard/shared/posix/socket_listen.cc", "//starboard/shared/posix/socket_receive_from.cc", - "//starboard/shared/posix/socket_resolve.cc", "//starboard/shared/posix/socket_send_to.cc", - "//starboard/shared/posix/socket_set_broadcast.cc", - "//starboard/shared/posix/socket_set_receive_buffer_size.cc", "//starboard/shared/posix/socket_set_reuse_address.cc", - "//starboard/shared/posix/socket_set_send_buffer_size.cc", - "//starboard/shared/posix/socket_set_tcp_keep_alive.cc", - "//starboard/shared/posix/socket_set_tcp_no_delay.cc", - "//starboard/shared/posix/socket_set_tcp_window_scaling.cc", "//starboard/shared/posix/storage_write_record.cc", "//starboard/shared/posix/system_break_into_debugger.cc", "//starboard/shared/posix/system_clear_last_error.cc", diff --git a/starboard/shared/libevent/socket_waiter_internal.cc b/starboard/shared/libevent/socket_waiter_internal.cc index 1720adc20d1b..53c2660f7117 100644 --- a/starboard/shared/libevent/socket_waiter_internal.cc +++ b/starboard/shared/libevent/socket_waiter_internal.cc @@ -33,16 +33,6 @@ namespace sbposix = starboard::shared::posix; -#if defined(_GNU_SOURCE) || defined(_POSIX_VERSION) -#if defined(PLAYSTATION_GENERATION) && (PLAYSTATION_GENERATION <= 5) -#define USE_POSIX_PIPE 0 -#else -#define USE_POSIX_PIPE 1 -#endif -#else -#define USE_POSIX_PIPE 0 -#endif - namespace { // We do this because it's our style to use explicitly-sized ints when not just // using int, but libevent uses shorts explicitly in its interface. @@ -57,68 +47,6 @@ SbSocketAddress GetIpv4Localhost() { address.address[3] = 1; return address; } - -SbSocket AcceptBySpinning(SbSocket server_socket, int64_t timeout) { - int64_t start = starboard::CurrentMonotonicTime(); - while (true) { - SbSocket accepted_socket = SbSocketAccept(server_socket); - if (SbSocketIsValid(accepted_socket)) { - return accepted_socket; - } - - // If we didn't get a socket, it should be pending. - SB_DCHECK(SbSocketGetLastError(server_socket) == kSbSocketPending); - - // Check if we have passed our timeout. - if (starboard::CurrentMonotonicTime() - start >= timeout) { - break; - } - - // Just being polite. - sched_yield(); - } - - return kSbSocketInvalid; -} - -#if !USE_POSIX_PIPE -void GetSocketPipe(SbSocket* client_socket, SbSocket* server_socket) { - int result; - SbSocketError sb_socket_result; - const int64_t kTimeoutUsec = 1'000'000 / 15; - SbSocketAddress address = GetIpv4Localhost(); - - // Setup a listening socket. - SbSocket listen_socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolTcp); - SB_DCHECK(SbSocketIsValid(listen_socket)); - result = SbSocketSetReuseAddress(listen_socket, true); - SB_DCHECK(result); - sb_socket_result = SbSocketBind(listen_socket, &address); - SB_DCHECK(sb_socket_result == kSbSocketOk); - sb_socket_result = SbSocketListen(listen_socket); - SB_DCHECK(sb_socket_result == kSbSocketOk); - // Update the address after a free port has been assigned. - SbSocketGetLocalAddress(listen_socket, &address); - - // Create a new socket to connect to the listening socket. - *client_socket = - SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolTcp); - SB_DCHECK(SbSocketIsValid(*client_socket)); - // This connect will probably return pending, but we'll assume it will connect - // eventually. - sb_socket_result = SbSocketConnect(*client_socket, &address); - SB_DCHECK(sb_socket_result == kSbSocketOk || - sb_socket_result == kSbSocketPending); - - // Spin until the accept happens (or we get impatient). - *server_socket = AcceptBySpinning(listen_socket, kTimeoutUsec); - SB_DCHECK(SbSocketIsValid(*server_socket)); - - result = SbSocketDestroy(listen_socket); - SB_DCHECK(result); -} -#endif } // namespace SbSocketWaiterPrivate::SbSocketWaiterPrivate() @@ -126,7 +54,6 @@ SbSocketWaiterPrivate::SbSocketWaiterPrivate() base_(event_base_new()), waiting_(false), woken_up_(false) { -#if USE_POSIX_PIPE int fds[2]; int result = pipe(fds); SB_DCHECK(result == 0); @@ -138,16 +65,6 @@ SbSocketWaiterPrivate::SbSocketWaiterPrivate() wakeup_write_fd_ = fds[1]; result = sbposix::SetNonBlocking(wakeup_write_fd_); SB_DCHECK(result); -#else - GetSocketPipe(&client_socket_, &server_socket_); - - // Set TCP_NODELAY on the server socket, so it immediately sends its tiny - // payload without waiting for more data. - SbSocketSetTcpNoDelay(server_socket_, true); - - wakeup_read_fd_ = client_socket_->socket_fd; - wakeup_write_fd_ = server_socket_->socket_fd; -#endif event_set(&wakeup_event_, wakeup_read_fd_, EV_READ | EV_PERSIST, &SbSocketWaiterPrivate::LibeventWakeUpCallback, this); @@ -173,13 +90,8 @@ SbSocketWaiterPrivate::~SbSocketWaiterPrivate() { event_del(&wakeup_event_); event_base_free(base_); -#if USE_POSIX_PIPE close(wakeup_read_fd_); close(wakeup_write_fd_); -#else - SbSocketDestroy(server_socket_); - SbSocketDestroy(client_socket_); -#endif } bool SbSocketWaiterPrivate::Add(int socket, @@ -547,5 +459,3 @@ SbSocketWaiterPrivate::Waitee* SbSocketWaiterPrivate::RemoveWaitee( sb_waitees_.erase(it); return result; } - -#undef USE_POSIX_PIPE diff --git a/starboard/shared/posix/socket_free_resolution.cc b/starboard/shared/posix/socket_free_resolution.cc deleted file mode 100644 index 4cab10913216..000000000000 --- a/starboard/shared/posix/socket_free_resolution.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include "starboard/common/log.h" - -void SbSocketFreeResolution(SbSocketResolution* resolution) { - if (!resolution) { - return; - } - - if (resolution->addresses) { - delete[] resolution->addresses; - } - - delete resolution; -} diff --git a/starboard/shared/posix/socket_is_connected.cc b/starboard/shared/posix/socket_is_connected.cc deleted file mode 100644 index 2325767cdb0b..000000000000 --- a/starboard/shared/posix/socket_is_connected.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include -#include - -#include "starboard/common/log.h" -#include "starboard/shared/posix/handle_eintr.h" -#include "starboard/shared/posix/socket_internal.h" - -bool SbSocketIsConnected(SbSocket socket) { - if (!SbSocketIsValid(socket)) { - return false; - } - - SB_DCHECK(socket->socket_fd >= 0); - - // To tell if it is really connected, we peek a byte from the stream. We - // should get a byte back, or an EAGAIN/EWOULDBLOCK telling us the socket is - // waiting for data. - char c; - int result = HANDLE_EINTR(recv(socket->socket_fd, &c, 1, MSG_PEEK)); - if (result == 0) { - return false; - } - - return (result > 0 || errno == EAGAIN || errno == EWOULDBLOCK); -} diff --git a/starboard/shared/posix/socket_is_connected_and_idle.cc b/starboard/shared/posix/socket_is_connected_and_idle.cc deleted file mode 100644 index 7ba32f0fcd68..000000000000 --- a/starboard/shared/posix/socket_is_connected_and_idle.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include -#include - -#include "starboard/common/log.h" -#include "starboard/shared/posix/handle_eintr.h" -#include "starboard/shared/posix/socket_internal.h" - -bool SbSocketIsConnectedAndIdle(SbSocket socket) { - if (!SbSocketIsValid(socket)) { - return false; - } - - SB_DCHECK(socket->socket_fd >= 0); - - // To tell if it is really connected and idle, we peek a byte from the - // stream. We should get an EAGAIN/EWOULDBLOCK telling us the socket is - // waiting for data. - char c; - int rv = HANDLE_EINTR(recv(socket->socket_fd, &c, 1, MSG_PEEK)); - if (rv >= 0) { - // Either not connected, or not idle. - return false; - } - - return (errno == EAGAIN || errno == EWOULDBLOCK); -} diff --git a/starboard/shared/posix/socket_join_multicast_group.cc b/starboard/shared/posix/socket_join_multicast_group.cc deleted file mode 100644 index 0dde43f02897..000000000000 --- a/starboard/shared/posix/socket_join_multicast_group.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include -#include -#include -#include - -#include "starboard/common/log.h" -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -bool SbSocketJoinMulticastGroup(SbSocket socket, - const SbSocketAddress* address) { - if (!SbSocketIsValid(socket)) { - errno = EBADF; - return false; - } - - if (!address) { - errno = EINVAL; - return false; - } - - SB_DCHECK(socket->socket_fd >= 0); - struct ip_mreq imreq = {0}; - in_addr_t in_addr = *reinterpret_cast(address->address); - imreq.imr_multiaddr.s_addr = in_addr; - imreq.imr_interface.s_addr = INADDR_ANY; - - int result = setsockopt(socket->socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - &imreq, sizeof(imreq)); - if (result != 0) { - SB_LOG(ERROR) << "Failed to IP_ADD_MEMBERSHIP on socket " - << socket->socket_fd << ", errno = " << errno; - socket->error = sbposix::TranslateSocketErrno(errno); - return false; - } - - socket->error = kSbSocketOk; - return true; -} diff --git a/starboard/shared/posix/socket_resolve.cc b/starboard/shared/posix/socket_resolve.cc deleted file mode 100644 index 283aee965ca5..000000000000 --- a/starboard/shared/posix/socket_resolve.cc +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include -#include -#include - -#include "starboard/common/log.h" -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -SbSocketResolution* SbSocketResolve(const char* hostname, int filters) { - struct addrinfo* ai = NULL; - struct addrinfo hints = {0}; - - if (filters & kSbSocketResolveFilterIpv4) { - if (filters & kSbSocketResolveFilterIpv6) { - hints.ai_family = AF_UNSPEC; - } else { - hints.ai_family = AF_INET; - } - } else if (filters & kSbSocketResolveFilterIpv6) { - hints.ai_family = AF_INET6; - } else { - hints.ai_family = AF_UNSPEC; - } - - hints.ai_flags = AI_ADDRCONFIG; - hints.ai_socktype = SOCK_STREAM; - - // Actually make the call to get the data. - int err = getaddrinfo(hostname, NULL, &hints, &ai); - if (err != 0 || ai == NULL) { - return NULL; - } - - int address_count = 0; - for (const struct addrinfo* i = ai; i != NULL; i = i->ai_next) { - ++address_count; - } - - SbSocketResolution* result = new SbSocketResolution(); - - // Translate all the sockaddrs. - sbposix::SockAddr* sock_addrs = new sbposix::SockAddr[address_count]; - bool* parsed = new bool[address_count]; - int index = 0; - int skip = 0; - for (const struct addrinfo* i = ai; i != NULL; i = i->ai_next, ++index) { - // Skip over any addresses we can't parse. - parsed[index] = sock_addrs[index].FromSockaddr(i->ai_addr); - if (!parsed[index]) { - ++skip; - } - } - - result->address_count = address_count - skip; - result->addresses = new SbSocketAddress[result->address_count]; - - int result_index = 0; - for (int i = 0; i < address_count; ++i) { - if (parsed[i] && - sock_addrs[i].ToSbSocketAddress(&result->addresses[result_index])) { - ++result_index; - } - } - - delete[] parsed; - delete[] sock_addrs; - freeaddrinfo(ai); - return result; -} diff --git a/starboard/shared/posix/socket_set_broadcast.cc b/starboard/shared/posix/socket_set_broadcast.cc deleted file mode 100644 index 3efc0e8df957..000000000000 --- a/starboard/shared/posix/socket_set_broadcast.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include - -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -bool SbSocketSetBroadcast(SbSocket socket, bool value) { - return sbposix::SetBooleanSocketOption(socket, SOL_SOCKET, SO_BROADCAST, - "SO_BROADCAST", value); -} diff --git a/starboard/shared/posix/socket_set_receive_buffer_size.cc b/starboard/shared/posix/socket_set_receive_buffer_size.cc deleted file mode 100644 index fdd4b649d997..000000000000 --- a/starboard/shared/posix/socket_set_receive_buffer_size.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include - -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -bool SbSocketSetReceiveBufferSize(SbSocket socket, int32_t size) { - return sbposix::SetIntegerSocketOption(socket, SOL_SOCKET, SO_RCVBUF, - "SO_RCVBUF", size); -} diff --git a/starboard/shared/posix/socket_set_send_buffer_size.cc b/starboard/shared/posix/socket_set_send_buffer_size.cc deleted file mode 100644 index 05e517101103..000000000000 --- a/starboard/shared/posix/socket_set_send_buffer_size.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include - -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -bool SbSocketSetSendBufferSize(SbSocket socket, int32_t size) { - return sbposix::SetIntegerSocketOption(socket, SOL_SOCKET, SO_SNDBUF, - "SO_SNDBUF", size); -} diff --git a/starboard/shared/posix/socket_set_tcp_keep_alive.cc b/starboard/shared/posix/socket_set_tcp_keep_alive.cc deleted file mode 100644 index 871cc12517eb..000000000000 --- a/starboard/shared/posix/socket_set_tcp_keep_alive.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include -#include - -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -bool SbSocketSetTcpKeepAlive(SbSocket socket, bool value, int64_t period) { - bool result = sbposix::SetBooleanSocketOption( - socket, SOL_SOCKET, SO_KEEPALIVE, "SO_KEEPALIVE", value); - if (!result) { - return false; - } - - int period_seconds = static_cast(period / 1'000'000); - result = sbposix::SetIntegerSocketOption(socket, SOL_TCP, TCP_KEEPIDLE, - "TCP_KEEPIDLE", period_seconds); - if (!result) { - return false; - } - - return sbposix::SetIntegerSocketOption(socket, SOL_TCP, TCP_KEEPINTVL, - "TCP_KEEPINTVL", period_seconds); -} diff --git a/starboard/shared/posix/socket_set_tcp_no_delay.cc b/starboard/shared/posix/socket_set_tcp_no_delay.cc deleted file mode 100644 index c4faaf6e9731..000000000000 --- a/starboard/shared/posix/socket_set_tcp_no_delay.cc +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -#include -#include - -#include "starboard/shared/posix/socket_internal.h" - -namespace sbposix = starboard::shared::posix; - -bool SbSocketSetTcpNoDelay(SbSocket socket, bool value) { - return sbposix::SetBooleanSocketOption(socket, IPPROTO_TCP, TCP_NODELAY, - "TCP_NODELAY", value); -} diff --git a/starboard/shared/posix/socket_set_tcp_window_scaling.cc b/starboard/shared/posix/socket_set_tcp_window_scaling.cc deleted file mode 100644 index 7aaa5f0ed695..000000000000 --- a/starboard/shared/posix/socket_set_tcp_window_scaling.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetTcpWindowScaling(SbSocket socket, bool value) { - // This API is not supported in standard POSIX. - return false; -} diff --git a/starboard/shared/starboard/net_args.cc b/starboard/shared/starboard/net_args.cc deleted file mode 100644 index afd1f2d4e542..000000000000 --- a/starboard/shared/starboard/net_args.cc +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright 2018 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/shared/starboard/net_args.h" - -#include - -#include -#include -#include - -#include "starboard/common/log.h" -#include "starboard/common/socket.h" -#include "starboard/common/time.h" -#include "starboard/socket_waiter.h" -#include "starboard/thread.h" - -#ifndef NET_ARGS_PORT -#define NET_ARGS_PORT 49355 -#endif - -// Controls whether using IPv4 or IPv6. -#ifndef NET_ARGS_IP_VERSION -#define NET_ARGS_IP_VERSION kSbSocketAddressTypeIpv4 -#endif - -namespace starboard { -namespace shared { -namespace starboard { -namespace { - -std::unique_ptr CreateListenSocket() { - std::unique_ptr socket( - new Socket(NET_ARGS_IP_VERSION, kSbSocketProtocolTcp)); - socket->SetReuseAddress(true); - SbSocketAddress sock_addr; - // Ip address will be set to 0.0.0.0 so that it will bind to all sockets. - memset(&sock_addr, 0, sizeof(SbSocketAddress)); - sock_addr.type = NET_ARGS_IP_VERSION; - sock_addr.port = NET_ARGS_PORT; - SbSocketError sock_err = socket->Bind(&sock_addr); - - const char kErrFmt[] = "Socket error while attempting to bind, error = %d\n"; - if (sock_err != kSbSocketOk) { - SbLogRawFormatF(kErrFmt, sock_err); - } - sock_err = socket->Listen(); - if (sock_err != kSbSocketOk) { - SbLogRawFormatF(kErrFmt, sock_err); - } - return socket; -} - -void WaitUntilReadableOrConnectionReset(SbSocket sock) { - SbSocketWaiter waiter = SbSocketWaiterCreate(); - - struct F { - static void WakeUp(SbSocketWaiter waiter, SbSocket, void*, int) { - SbSocketWaiterWakeUp(waiter); - } - }; - - SbSocketWaiterAdd(waiter, sock, NULL, &F::WakeUp, kSbSocketWaiterInterestRead, - false); // false means one shot. - - SbSocketWaiterWait(waiter); - SbSocketWaiterRemove(waiter, sock); - SbSocketWaiterDestroy(waiter); -} - -std::unique_ptr WaitForClientConnection(Socket* listen_sock, - int64_t timeout) { - int64_t expire_time = (timeout >= 0) && (timeout < kSbInt64Max) - ? CurrentMonotonicTime() + timeout - : kSbInt64Max; - while (true) { - std::unique_ptr client_connection(listen_sock->Accept()); - if (client_connection) { - return client_connection; - } - if (CurrentMonotonicTime() > expire_time) { - return std::unique_ptr(); - } - usleep(1000); - } -} - -std::vector SplitStringByLines(const std::string& string_buff) { - std::vector lines; - std::stringstream ss; - ss << string_buff; - for (std::string line; std::getline(ss, line);) { - if (!line.empty()) { - lines.push_back(line); - } - } - return lines; -} - -} // namespace. - -// Command line switch useful for determining if NetArgsWaitForConnection() -// should be called. -const char kNetArgsCommandSwitchWait[] = "net_args_wait_for_connection"; - -std::vector NetArgsWaitForPayload(int64_t timeout) { - std::unique_ptr listen = CreateListenSocket(); - std::unique_ptr client_connection = - WaitForClientConnection(listen.get(), timeout); - if (!client_connection) { - SB_LOG(ERROR) << "Timed out waiting for net args."; - return std::vector(); - } - - std::string str_buff; - - while (true) { - char buff[128]; - int result = client_connection->ReceiveFrom(buff, sizeof(buff), NULL); - if (result > 0) { - str_buff.append(buff, static_cast(result)); - continue; - } else if (result == 0) { - // Socket has closed. - break; - } else if (result < 0) { // Handle error condition. - SbSocketError err = client_connection->GetLastError(); - client_connection->ClearLastError(); - - switch (err) { - case kSbSocketOk: { - SB_NOTREACHED() << "Expected error condition when return val " - << "is < 0."; - continue; - } - case kSbSocketPending: { - WaitUntilReadableOrConnectionReset(client_connection->socket()); - continue; - } - default: { - break; - } - } - } - } - return SplitStringByLines(str_buff); -} - -} // namespace starboard -} // namespace shared -} // namespace starboard diff --git a/starboard/shared/starboard/net_args.h b/starboard/shared/starboard/net_args.h deleted file mode 100644 index fcee5cd24170..000000000000 --- a/starboard/shared/starboard/net_args.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2018 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// NetArgs is an optional component that allows socket access to tell an -// executable what it's command args are. -// -// ****** // -// TODO: Remove the following: -// It's recommended to call NetLogWaitForClientConnected() to ensure that the -// NetLog is running a predictable time from launch. It's also STRONGLY -// recommended that NetLogFlushThenClose() is called during shutdown to -// guarantee that any pending data is flushed out through the network layer. -// Failure to do this will often result in the netlog being truncated as the -// process shuts down. -// -// The netlog create a server that will bind to ip 0.0.0.0 (and similar in -// ipv6) and will listen for client connections. See net_log.cc for which -// port net_log will listen to. -// -// See also net_log.py for an example script that can connect to a running -// netlog instance. - -#ifndef STARBOARD_SHARED_STARBOARD_NET_ARGS_H_ -#define STARBOARD_SHARED_STARBOARD_NET_ARGS_H_ - -#include -#include - -namespace starboard { -namespace shared { -namespace starboard { - -// Command line switch useful for determining if NetArgsWaitForConnection() -// should be called. -extern const char kNetArgsCommandSwitchWait[]; - -// Waits until args stream in with a socket connection and data reception. -// Timeout is in microseconds. A timeout value of < 0 will signal infinite -// timeout. -std::vector NetArgsWaitForPayload(int64_t timeout); - -} // namespace starboard -} // namespace shared -} // namespace starboard - -#endif // STARBOARD_SHARED_STARBOARD_NET_ARGS_H_ diff --git a/starboard/shared/stub/socket_free_resolution.cc b/starboard/shared/stub/socket_free_resolution.cc deleted file mode 100644 index 4f34a1529d31..000000000000 --- a/starboard/shared/stub/socket_free_resolution.cc +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -void SbSocketFreeResolution(SbSocketResolution* resolution) {} diff --git a/starboard/shared/stub/socket_is_connected.cc b/starboard/shared/stub/socket_is_connected.cc deleted file mode 100644 index 33cfe81191e5..000000000000 --- a/starboard/shared/stub/socket_is_connected.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketIsConnected(SbSocket socket) { - return false; -} diff --git a/starboard/shared/stub/socket_is_connected_and_idle.cc b/starboard/shared/stub/socket_is_connected_and_idle.cc deleted file mode 100644 index a2001a33458b..000000000000 --- a/starboard/shared/stub/socket_is_connected_and_idle.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketIsConnectedAndIdle(SbSocket socket) { - return false; -} diff --git a/starboard/shared/stub/socket_join_multicast_group.cc b/starboard/shared/stub/socket_join_multicast_group.cc deleted file mode 100644 index ae57ab51b92a..000000000000 --- a/starboard/shared/stub/socket_join_multicast_group.cc +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketJoinMulticastGroup(SbSocket socket, - const SbSocketAddress* address) { - return false; -} diff --git a/starboard/shared/stub/socket_resolve.cc b/starboard/shared/stub/socket_resolve.cc deleted file mode 100644 index 51ad4c25fac0..000000000000 --- a/starboard/shared/stub/socket_resolve.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -SbSocketResolution* SbSocketResolve(const char* hostname, int filters) { - return NULL; -} diff --git a/starboard/shared/stub/socket_set_broadcast.cc b/starboard/shared/stub/socket_set_broadcast.cc deleted file mode 100644 index 9ce4e748024d..000000000000 --- a/starboard/shared/stub/socket_set_broadcast.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetBroadcast(SbSocket socket, bool value) { - return false; -} diff --git a/starboard/shared/stub/socket_set_receive_buffer_size.cc b/starboard/shared/stub/socket_set_receive_buffer_size.cc deleted file mode 100644 index 70cca39f60a9..000000000000 --- a/starboard/shared/stub/socket_set_receive_buffer_size.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetReceiveBufferSize(SbSocket socket, int32_t size) { - return false; -} diff --git a/starboard/shared/stub/socket_set_send_buffer_size.cc b/starboard/shared/stub/socket_set_send_buffer_size.cc deleted file mode 100644 index 9476284e338e..000000000000 --- a/starboard/shared/stub/socket_set_send_buffer_size.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetSendBufferSize(SbSocket socket, int32_t size) { - return false; -} diff --git a/starboard/shared/stub/socket_set_tcp_keep_alive.cc b/starboard/shared/stub/socket_set_tcp_keep_alive.cc deleted file mode 100644 index 40f35b716612..000000000000 --- a/starboard/shared/stub/socket_set_tcp_keep_alive.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetTcpKeepAlive(SbSocket socket, bool value, int64_t period) { - return false; -} diff --git a/starboard/shared/stub/socket_set_tcp_no_delay.cc b/starboard/shared/stub/socket_set_tcp_no_delay.cc deleted file mode 100644 index b02955849f28..000000000000 --- a/starboard/shared/stub/socket_set_tcp_no_delay.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetTcpNoDelay(SbSocket socket, bool value) { - return false; -} diff --git a/starboard/shared/stub/socket_set_tcp_window_scaling.cc b/starboard/shared/stub/socket_set_tcp_window_scaling.cc deleted file mode 100644 index 769c13625eb0..000000000000 --- a/starboard/shared/stub/socket_set_tcp_window_scaling.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/common/socket.h" - -bool SbSocketSetTcpWindowScaling(SbSocket socket, bool value) { - return false; -} diff --git a/starboard/socket.h b/starboard/socket.h index f6999c93dba3..c65225e1e34c 100644 --- a/starboard/socket.h +++ b/starboard/socket.h @@ -207,22 +207,6 @@ SB_EXPORT SbSocketError SbSocketListen(SbSocket socket); // |socket|: The SbSocket that is accepting a pending connection. SB_EXPORT SbSocket SbSocketAccept(SbSocket socket); -// DEPRECATED with SB_API_VERSION 16 -// -// Indicates whether |socket| is connected to anything. Invalid sockets are not -// connected. -// -// |socket|: The SbSocket to be checked. -SB_EXPORT bool SbSocketIsConnected(SbSocket socket); - -// DEPRECATED with SB_API_VERSION 16 -// -// Returns whether |socket| is connected to anything, and, if so, whether it is -// receiving any data. -// -// |socket|: The SbSocket to be checked. -SB_EXPORT bool SbSocketIsConnectedAndIdle(SbSocket socket); - // DEPRECATED with SB_API_VERSION 16 // // Returns the last error set on |socket|. If |socket| is not valid, this @@ -344,18 +328,6 @@ SB_EXPORT int SbSocketSendTo(SbSocket socket, int data_size, const SbSocketAddress* destination); -// DEPRECATED with SB_API_VERSION 16 -// -// Sets the |SO_BROADCAST|, or equivalent, option to |value| on |socket|. The -// return value indicates whether the option was actually set. -// -// This option is only meaningful for UDP sockets and allows the socket to -// send to the broadcast address. -// -// |socket|: The SbSocket for which the option is set. -// |value|: The new value for the option. -SB_EXPORT bool SbSocketSetBroadcast(SbSocket socket, bool value); - // DEPRECATED with SB_API_VERSION 16 // // Sets the |SO_REUSEADDR|, or equivalent, option to |value| on |socket|. @@ -368,96 +340,6 @@ SB_EXPORT bool SbSocketSetBroadcast(SbSocket socket, bool value); // |value|: The new value for the option. SB_EXPORT bool SbSocketSetReuseAddress(SbSocket socket, bool value); -// DEPRECATED with SB_API_VERSION 16 -// -// Sets the |SO_RCVBUF|, or equivalent, option to |size| on |socket|. The -// return value indicates whether the option was actually set. -// -// |socket|: The SbSocket for which the option is set. -// |size|: The value for the option. -SB_EXPORT bool SbSocketSetReceiveBufferSize(SbSocket socket, int32_t size); - -// DEPRECATED with SB_API_VERSION 16 -// -// Sets the |SO_SNDBUF|, or equivalent, option to |size| on |socket|. The -// return value indicates whether the option was actually set. -// -// |socket|: The SbSocket for which the option is set. -// |size|: The value for the option. -SB_EXPORT bool SbSocketSetSendBufferSize(SbSocket socket, int32_t size); - -// DEPRECATED with SB_API_VERSION 16 -// -// Sets the |SO_KEEPALIVE|, or equivalent, option to |value| on |socket|. The -// return value indicates whether the option was actually set. -// -// |socket|: The SbSocket for which the option is set. -// |value|: If set to |true|, then |period| specifies the minimum time in -// microseconds between keep-alive packets. If set to |false|, |period| -// is ignored. -// |period|: The time in microseconds between keep-alive packets. This value -// is only relevant if |value| is |true|. -SB_EXPORT bool SbSocketSetTcpKeepAlive(SbSocket socket, - bool value, - int64_t period); - -// DEPRECATED with SB_API_VERSION 16 -// -// Sets the |TCP_NODELAY|, or equivalent, option to |value| on |socket|. The -// return value indicates whether the option was actually set. -// -// This function disables the Nagle algorithm for reducing the number of -// packets sent when converting from a stream to packets. Disabling Nagle -// generally puts the data for each Send call into its own packet, but does -// not guarantee that behavior. -// -// |socket|: The SbSocket for which the option is set. -// |value|: Indicates whether the Nagle algorithm should be disabled -// (|value|=|true|). -SB_EXPORT bool SbSocketSetTcpNoDelay(SbSocket socket, bool value); - -// DEPRECATED with SB_API_VERSION 16 -// -// Sets the |SO_WINSCALE|, or equivalent, option to |value| on |socket|. The -// return value indicates whether the option was actually set. -// -// |socket|: The SbSocket for which the option is set. -// |value|: The value for the option. -SB_EXPORT bool SbSocketSetTcpWindowScaling(SbSocket socket, bool value); - -// DEPRECATED with SB_API_VERSION 16 -// -// Joins |socket| to an IP multicast group identified by |address|. The -// equivalent of IP_ADD_MEMBERSHIP. The return value indicates whether the -// socket was joined to the group successfully. -// -// |socket|: The SbSocket to be joined to the IP multicast group. -// |address|: The location of the IP multicast group. -SB_EXPORT bool SbSocketJoinMulticastGroup(SbSocket socket, - const SbSocketAddress* address); - -// DEPRECATED with SB_API_VERSION 16 -// -// Synchronously resolves |hostname| into the returned SbSocketResolution, -// which must be freed with SbSocketFreeResolution. The function returns -// |NULL| if it is unable to resolve |hostname|. -// -// |hostname|: The hostname to be resolved. -// |filters|: A mask of SbSocketResolveFilter values used to filter the -// resolution. If |filters| does not specify an IP address family filter, -// all address families are included. However, if one IP address family filter -// is specified, only that address family is included. The function ignores -// unrecognized filter bits. -SB_EXPORT SbSocketResolution* SbSocketResolve(const char* hostname, - int filters); - -// DEPRECATED with SB_API_VERSION 16 -// -// Frees a resolution allocated by SbSocketResolve. -// -// |resolution|: The resolution to be freed. -SB_EXPORT void SbSocketFreeResolution(SbSocketResolution* resolution); - #ifdef __cplusplus } // extern "C" #endif diff --git a/starboard/stub/BUILD.gn b/starboard/stub/BUILD.gn index 3849d53dab8f..11c149c10fcc 100644 --- a/starboard/stub/BUILD.gn +++ b/starboard/stub/BUILD.gn @@ -107,25 +107,14 @@ static_library("stub_sources") { "//starboard/shared/stub/socket_connect.cc", "//starboard/shared/stub/socket_create.cc", "//starboard/shared/stub/socket_destroy.cc", - "//starboard/shared/stub/socket_free_resolution.cc", "//starboard/shared/stub/socket_get_interface_address.cc", "//starboard/shared/stub/socket_get_last_error.cc", "//starboard/shared/stub/socket_get_local_address.cc", - "//starboard/shared/stub/socket_is_connected.cc", - "//starboard/shared/stub/socket_is_connected_and_idle.cc", "//starboard/shared/stub/socket_is_ipv6_supported.cc", - "//starboard/shared/stub/socket_join_multicast_group.cc", "//starboard/shared/stub/socket_listen.cc", "//starboard/shared/stub/socket_receive_from.cc", - "//starboard/shared/stub/socket_resolve.cc", "//starboard/shared/stub/socket_send_to.cc", - "//starboard/shared/stub/socket_set_broadcast.cc", - "//starboard/shared/stub/socket_set_receive_buffer_size.cc", "//starboard/shared/stub/socket_set_reuse_address.cc", - "//starboard/shared/stub/socket_set_send_buffer_size.cc", - "//starboard/shared/stub/socket_set_tcp_keep_alive.cc", - "//starboard/shared/stub/socket_set_tcp_no_delay.cc", - "//starboard/shared/stub/socket_set_tcp_window_scaling.cc", "//starboard/shared/stub/socket_waiter_add.cc", "//starboard/shared/stub/socket_waiter_create.cc", "//starboard/shared/stub/socket_waiter_destroy.cc", From a824a7e9f67194b6191ec67010d99627e0bf66d2 Mon Sep 17 00:00:00 2001 From: Miguel Casas-Sanchez Date: Fri, 27 Sep 2024 10:57:13 -0700 Subject: [PATCH 4/5] starboard/types.h: Remove some unused types As said, kSb(U)Int8(Min|Max) are not used anywhere [1]. This CL removes them. Verified bya local x64x11 build. [1] https://source.corp.google.com/h/lbshell-internal/cobalt_src/+/COBALT:starboard/types.h?q=kSb.%3FInt(8)&ss=h%2Flbshell-internal%2Fcobalt_src%2F%2B%2Frefs%2Fheads%2FCOBALT b/366064934 --- starboard/types.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/starboard/types.h b/starboard/types.h index 0d36dd378d80..f8af0615249b 100644 --- a/starboard/types.h +++ b/starboard/types.h @@ -57,10 +57,6 @@ typedef int64_t ssize_t; // Simulate needed portions of limits.h for platforms that don't provide it. -static const int8_t kSbInt8Min = ((int8_t)0x80); -static const int8_t kSbInt8Max = ((int8_t)0x7F); -static const uint8_t kSbUInt8Max = ((uint8_t)0xFF); - static const int16_t kSbInt16Min = ((int16_t)0x8000); static const int16_t kSbInt16Max = ((int16_t)0x7FFF); static const uint16_t kSbUInt16Max = ((uint16_t)0xFFFF); From 13ca7cdb416878326d40a88e889dac0e6bbfdf35 Mon Sep 17 00:00:00 2001 From: Oscar Vestlie Date: Mon, 30 Sep 2024 13:00:46 -0700 Subject: [PATCH 5/5] Polish test result upload (#4156) * Use DataDog's test attributes in tags https://docs.datadoghq.com/tests/#test-configuration-attributes * Move log printout to the end of the action b/288331664 --- .github/actions/on_device_tests/action.yaml | 28 +++++++++++++-------- .github/actions/on_host_test/action.yaml | 4 +-- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/actions/on_device_tests/action.yaml b/.github/actions/on_device_tests/action.yaml index 82e3c786ee64..a0044996e80b 100644 --- a/.github/actions/on_device_tests/action.yaml +++ b/.github/actions/on_device_tests/action.yaml @@ -116,36 +116,33 @@ runs: sleep 10 # The log files are named by the device lab test driver. - COBALT_ERROR_LOG="webDriverTestLog.ERROR" - COBALT_INFO_LOG="webDriverTestLog.INFO" + COBALT_ERROR_LOG_FILENAME="webDriverTestLog.ERROR" + COBALT_INFO_LOG_FILENAME="webDriverTestLog.INFO" # This command will fail until the results have been uploaded. - gsutil cp "${GCS_RESULTS_PATH}/${COBALT_ERROR_LOG}" . - gsutil cp "${GCS_RESULTS_PATH}/${COBALT_INFO_LOG}" . + gsutil cp "${GCS_RESULTS_PATH}/${COBALT_ERROR_LOG_FILENAME}" . + gsutil cp "${GCS_RESULTS_PATH}/${COBALT_INFO_LOG_FILENAME}" . gsutil cp "${GCS_RESULTS_PATH}/${COBALT_XMLS_FILENAME}" . # Break if all files were downloaded. - if [[ -f "${COBALT_XMLS_FILENAME}" && -f "${COBALT_ERROR_LOG}" && -f "${COBALT_INFO_LOG}" ]]; then + if [[ -f "${COBALT_XMLS_FILENAME}" && -f "${COBALT_ERROR_LOG_FILENAME}" && -f "${COBALT_INFO_LOG_FILENAME}" ]]; then break fi i=$(( ${i} + 1 )) done - # Print device logs. Might fail if the log file failed to download. - cat ${COBALT_ERROR_LOG} - # Rename log files for archiving to not expose legacy weirdness. mkdir -p "${COBALT_LOGS_DIR}/${{ matrix.platform }}/" - mv "${COBALT_ERROR_LOG}" "${COBALT_LOGS_DIR}/${{ matrix.platform }}/stderr_${{ matrix.shard }}.log" - mv "${COBALT_INFO_LOG}" "${COBALT_LOGS_DIR}/${{ matrix.platform }}/stdout_${{ matrix.shard }}.log" + cp "${COBALT_ERROR_LOG_FILENAME}" "${COBALT_LOGS_DIR}/${{ matrix.platform }}/stderr_${{ matrix.shard }}.log" + cp "${COBALT_INFO_LOG_FILENAME}" "${COBALT_LOGS_DIR}/${{ matrix.platform }}/stdout_${{ matrix.shard }}.log" # Prepare unit test results for DataDog upload. RESULT_PATH=${UNIT_TEST_RESULT_PATH}/${{ matrix.platform }}/${{ matrix.shard }}/ mkdir -p ${RESULT_PATH} # Set tags for test differentiation. - tags="platform:${{ matrix.platform }}" + tags="os.platform:${{ matrix.platform }}" echo $tags > ${UNIT_TEST_RESULT_PATH}/${{ matrix.platform }}/TAGS unzip ${COBALT_XMLS_FILENAME} -d ${RESULT_PATH} @@ -162,3 +159,12 @@ runs: with: name: unit-test-results path: ${{ env.UNIT_TEST_RESULT_PATH }}/ + - name: Print device logs + if: always() + run: | + if ls ${COBALT_LOGS_DIR}/**/*.log 1> /dev/null 2>&1; then + cat ${COBALT_LOGS_DIR}/**/*.log + else + echo "No device logs found" + fi + shell: bash diff --git a/.github/actions/on_host_test/action.yaml b/.github/actions/on_host_test/action.yaml index 2276acdc37ed..20bfa46a7786 100644 --- a/.github/actions/on_host_test/action.yaml +++ b/.github/actions/on_host_test/action.yaml @@ -100,8 +100,8 @@ runs: shell: bash run: | # Set tags for test differentiation. - tags="platform:${{ matrix.platform }}" - tags="${tags},os:${{ inputs.os }}" + tags="os.platform:${{ matrix.platform }}" + tags="${tags},os.family:${{ inputs.os }}" echo $tags > ${TEST_RESULTS_DIR}/${{ matrix.platform }}/TAGS - name: Archive unit test results uses: actions/upload-artifact@v3