Skip to content

Commit

Permalink
Remove socket and socket waiter headers
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurajayaraman committed Nov 19, 2024
1 parent 0b48dd2 commit 3b3c8fe
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 552 deletions.
12 changes: 6 additions & 6 deletions starboard/android/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static_library("starboard_platform") {
"//starboard/shared/posix/memory_free_aligned.cc",
"//starboard/shared/posix/page_internal.cc",
"//starboard/shared/posix/set_non_blocking_internal.cc",
"//starboard/shared/posix/socket_internal.cc",
"//starboard/shared/posix/socket_is_ipv6_supported.cc",
"//starboard/shared/posix/storage_write_record.cc",
"//starboard/shared/posix/system_break_into_debugger.cc",
"//starboard/shared/posix/system_clear_last_error.cc",
Expand Down Expand Up @@ -278,11 +278,11 @@ static_library("starboard_platform") {
"posix_emu/pthread.cc",
"posix_emu/stat.cc",
"sanitizer_options.cc",

#"speech_synthesis_cancel.cc",
#"speech_synthesis_internal.cc",
#"speech_synthesis_is_supported.cc",
#"speech_synthesis_speak.cc",
"socket_get_interface_address.cc",
"speech_synthesis_cancel.cc",
"speech_synthesis_internal.cc",
"speech_synthesis_is_supported.cc",
"speech_synthesis_speak.cc",
"system_get_extensions.cc",
"system_get_locale_id.cc",
"system_get_path.cc",
Expand Down
44 changes: 1 addition & 43 deletions starboard/common/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,7 @@
#include "starboard/common/log.h"
#include "starboard/configuration.h"

namespace starboard {

SbSocketAddress GetUnspecifiedAddress(SbSocketAddressType address_type,
int port) {
SbSocketAddress address = {};
address.type = address_type;
address.port = port;
return address;
}

bool GetLocalhostAddress(SbSocketAddressType address_type,
int port,
SbSocketAddress* address) {
if (address_type != kSbSocketAddressTypeIpv4 &&
address_type != kSbSocketAddressTypeIpv6) {
SB_LOG(ERROR) << __FUNCTION__ << ": unknown address type: " << address_type;
return false;
}
*address = GetUnspecifiedAddress(address_type, port);
switch (address_type) {
case kSbSocketAddressTypeIpv4:
address->address[0] = 127;
address->address[3] = 1;
break;
case kSbSocketAddressTypeIpv6:
address->address[15] = 1;
break;
}

return true;
}

bool Socket::IsValid() {
return SbSocketIsValid(socket_);
}

SbSocket Socket::socket() {
return socket_;
}

Socket::Socket(SbSocket socket) : socket_(socket) {}

} // namespace starboard
namespace starboard {} // namespace starboard

std::ostream& operator<<(std::ostream& os, const SbSocketAddress& address) {
if (address.type == kSbSocketAddressTypeIpv6) {
Expand Down
57 changes: 1 addition & 56 deletions starboard/common/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,7 @@
#include "starboard/socket.h"
#include "starboard/types.h"

namespace starboard {

// Returns an IP unspecified address with the given port.
SbSocketAddress GetUnspecifiedAddress(SbSocketAddressType address_type,
int port);

// Gets an IP localhost address with the given port.
// Returns true if it was successful.
bool GetLocalhostAddress(SbSocketAddressType address_type,
int port,
SbSocketAddress* address);

class Socket {
public:
Socket(SbSocketAddressType address_type, SbSocketProtocol protocol);
explicit Socket(SbSocketAddressType address_type);
explicit Socket(SbSocketProtocol protocol);
Socket();
~Socket();
bool IsValid();

SbSocketError Connect(const SbSocketAddress* address);
SbSocketError Bind(const SbSocketAddress* local_address);
SbSocketError Listen();
Socket* Accept();

bool IsConnected();
bool IsConnectedAndIdle();
bool IsPending();

SbSocketError GetLastError();
void ClearLastError();

int ReceiveFrom(char* out_data, int data_size, SbSocketAddress* out_source);
int SendTo(const char* data,
int data_size,
const SbSocketAddress* destination);

bool GetLocalAddress(SbSocketAddress* out_address);
bool SetBroadcast(bool value);
bool SetReuseAddress(bool value);
bool SetReceiveBufferSize(int32_t size);
bool SetSendBufferSize(int32_t size);
bool SetTcpKeepAlive(bool value, int64_t period); // period in microseconds.
bool SetTcpNoDelay(bool value);
bool SetTcpWindowScaling(bool value);

SbSocket socket();

private:
explicit Socket(SbSocket socket);

SbSocket socket_;
};

} // namespace starboard
namespace starboard {} // namespace starboard

// Let SbSocketAddresses be output to log streams.
std::ostream& operator<<(std::ostream& os, const SbSocketAddress& address);
Expand Down
3 changes: 2 additions & 1 deletion starboard/common/socket_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 0
#include "starboard/common/socket.h"

#include "starboard/common/log.h"
Expand Down Expand Up @@ -59,3 +59,4 @@ TEST(SocketTest, TestGetLocalhostAddressInvalidType) {
}
} // namespace
} // namespace starboard
#endif
5 changes: 3 additions & 2 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ ExportedSymbols::ExportedSymbols() {
REGISTER_SYMBOL(SbPlayerSetVolume);
REGISTER_SYMBOL(SbPlayerWriteEndOfStream);
REGISTER_SYMBOL(SbPlayerWriteSamples);
REGISTER_SYMBOL(SbSocketWaiterAdd);
REGISTER_SYMBOL(SbSocketIsIpv6Supported);
// REGISTER_SYMBOL(SbSocketWaiterAdd);
REGISTER_SYMBOL(SbSocketWaiterCreate);
REGISTER_SYMBOL(SbSocketWaiterDestroy);
REGISTER_SYMBOL(SbSocketWaiterRemove);
// REGISTER_SYMBOL(SbSocketWaiterRemove);
REGISTER_SYMBOL(SbSocketWaiterWait);
REGISTER_SYMBOL(SbSocketWaiterWaitTimed);
REGISTER_SYMBOL(SbSocketWaiterWakeUp);
Expand Down
1 change: 1 addition & 0 deletions starboard/linux/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static_library("starboard_platform_sources") {
"//starboard/shared/posix/page_internal.cc",
"//starboard/shared/posix/set_non_blocking_internal.cc",
"//starboard/shared/posix/socket_internal.cc",
"//starboard/shared/posix/socket_is_ipv6_supported.cc",
"//starboard/shared/posix/storage_write_record.cc",
"//starboard/shared/posix/system_break_into_debugger.cc",
"//starboard/shared/posix/system_clear_last_error.cc",
Expand Down
28 changes: 0 additions & 28 deletions starboard/nplb/socket_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,6 @@ static inline void TimedWaitShouldBlock(SbSocketWaiter waiter,
EXPECT_LE(timeout, TimedWaitTimed(waiter, timeout));
}

// Socket operations may return specific (e.g. kSbSocketErrorConnectionReset) or
// general (e.g. kSbSocketErrorFailed) error codes, and while in some cases
// it may be important that we obtain a specific error message, in other cases
// it will just be used as a hint and so these methods are provided to make
// it easy to test against specific or general errors.
static inline bool SocketErrorIn(
SbSocketError error,
const std::vector<SbSocketError>& expected_set) {
for (size_t i = 0; i < expected_set.size(); ++i) {
if (expected_set[i] == error) {
return true;
}
}
return false;
}

#define EXPECT_SB_SOCKET_ERROR_IN(error, ...) \
do { \
EXPECT_TRUE(SocketErrorIn(error, {__VA_ARGS__})) \
<< "With " #error " = " << error; \
} while (false)

#define EXPECT_SB_SOCKET_ERROR_IS_ERROR(error) \
do { \
EXPECT_FALSE(SocketErrorIn(error, {kSbSocketOk, kSbSocketPending})) \
<< "With " #error " = " << error; \
} while (false)

} // namespace nplb
} // namespace starboard

Expand Down
2 changes: 1 addition & 1 deletion starboard/raspi/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static_library("starboard_platform_sources") {
"//starboard/shared/posix/memory_free_aligned.cc",
"//starboard/shared/posix/page_internal.cc",
"//starboard/shared/posix/set_non_blocking_internal.cc",
"//starboard/shared/posix/socket_internal.cc",
"//starboard/shared/posix/socket_is_ipv6_supported.cc",
"//starboard/shared/posix/storage_write_record.cc",
"//starboard/shared/posix/system_break_into_debugger.cc",
"//starboard/shared/posix/system_clear_last_error.cc",
Expand Down
29 changes: 0 additions & 29 deletions starboard/shared/libevent/socket_waiter_add.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,6 @@
#include "starboard/shared/libevent/socket_waiter_internal.h"
#include "starboard/socket.h"

bool SbSocketWaiterAdd(SbSocketWaiter waiter,
SbSocket socket,
void* context,
SbSocketWaiterCallback callback,
int interests,
bool persistent) {
if (!SbSocketWaiterIsValid(waiter)) {
SB_DLOG(ERROR) << __FUNCTION__ << ": Waiter (" << waiter << ") is invalid.";
return false;
}

if (!SbSocketIsValid(socket)) {
SB_DLOG(ERROR) << __FUNCTION__ << ": Socket (" << socket << ") is invalid.";
return false;
}

if (!callback) {
SB_DLOG(ERROR) << __FUNCTION__ << ": No callback provided.";
return false;
}

if (!interests) {
SB_DLOG(ERROR) << __FUNCTION__ << ": No interests provided.";
return false;
}

return waiter->Add(socket, context, callback, interests, persistent);
}

bool SbPosixSocketWaiterAdd(SbSocketWaiter waiter,
int socket,
void* context,
Expand Down
Loading

0 comments on commit 3b3c8fe

Please sign in to comment.