Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Clean up socket and socket_waiter headers #4454

Open
wants to merge 4 commits into
base: pre-chrobalt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions cobalt/network/dial/dial_http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ absl::optional<net::IPEndPoint> GetLocalIpAddress() {
SbSocketAddress destination;
memset(&(destination.address), 0, sizeof(destination.address));
destination.type = address_types;
if (!SbSocketGetInterfaceAddress(&destination, &local_ip, NULL) ||
!ip_addr.FromSbSocketAddress(&local_ip)) {
DLOG(WARNING) << "Unable to get a local interface address.";
return absl::nullopt;
}

return ip_addr;
}
Expand Down Expand Up @@ -134,9 +129,6 @@ int DialHttpServer::GetLocalAddress(net::IPEndPoint* addr) {

// DIAL only works with IPv4.
destination.type = kSbSocketAddressTypeIpv4;
if (!SbSocketGetInterfaceAddress(&destination, &local_ip, NULL)) {
return net::ERR_FAILED;
}
local_ip.port = addr->port();
LOG(INFO) << "In-App DIAL Address http://" << addr->address().ToString()
<< ":" << addr->port();
Expand Down
3 changes: 0 additions & 3 deletions cobalt/network/local_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ bool IsLocalIP(const SbSocketAddress& ip, const SbSocketAddress& source_address,
bool IsIPInLocalNetwork(const SbSocketAddress& destination) {
SbSocketAddress source_address;
SbSocketAddress netmask;
if (!(SbSocketGetInterfaceAddress(&destination, &source_address, &netmask))) {
return false;
}
return IsLocalIP(destination, source_address, netmask);
}

Expand Down
7 changes: 0 additions & 7 deletions net/server/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ int HttpServer::GetLocalInterfaceAddress(IPEndPoint* address) {
SbSocketAddress interface_address;
// Prefer to report the interface's IPv4 address.
any_ip.type = kSbSocketAddressTypeIpv4;
if (!SbSocketGetInterfaceAddress(&any_ip, &interface_address, nullptr)) {
any_ip.type = kSbSocketAddressTypeIpv6;
if (!SbSocketGetInterfaceAddress(&any_ip, &interface_address, nullptr)) {
DLOG(ERROR) << "Error getting interface address.";
return ERR_FAILED;
}
}
interface_address.port = address->port();
if (!address->FromSbSocketAddress(&interface_address)) {
DLOG(ERROR) << "Error converting socket address.";
Expand Down
11 changes: 0 additions & 11 deletions starboard/android/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +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_accept.cc",
"//starboard/shared/posix/socket_bind.cc",
"//starboard/shared/posix/socket_connect.cc",
"//starboard/shared/posix/socket_create.cc",
"//starboard/shared/posix/socket_destroy.cc",
"//starboard/shared/posix/socket_get_local_address.cc",
"//starboard/shared/posix/socket_internal.cc",
"//starboard/shared/posix/socket_is_ipv6_supported.cc",
"//starboard/shared/posix/socket_listen.cc",
"//starboard/shared/posix/socket_receive_from.cc",
"//starboard/shared/posix/socket_set_reuse_address.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 @@ -288,7 +278,6 @@ static_library("starboard_platform") {
"posix_emu/pthread.cc",
"posix_emu/stat.cc",
"sanitizer_options.cc",
"socket_get_interface_address.cc",
"speech_synthesis_cancel.cc",
"speech_synthesis_internal.cc",
"speech_synthesis_is_supported.cc",
Expand Down
87 changes: 0 additions & 87 deletions starboard/android/shared/socket_get_interface_address.cc

This file was deleted.

95 changes: 1 addition & 94 deletions starboard/common/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,100 +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;
}

Socket::Socket(SbSocketAddressType address_type, SbSocketProtocol protocol)
: socket_(SbSocketCreate(address_type, protocol)) {}

Socket::Socket(SbSocketAddressType address_type)
: socket_(SbSocketCreate(address_type, kSbSocketProtocolTcp)) {}

Socket::Socket(SbSocketProtocol protocol)
: socket_(SbSocketCreate(kSbSocketAddressTypeIpv4, protocol)) {}

Socket::Socket()
: socket_(SbSocketCreate(kSbSocketAddressTypeIpv4, kSbSocketProtocolTcp)) {}

Socket::~Socket() {
SbSocketDestroy(socket_);
}

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

SbSocketError Socket::Connect(const SbSocketAddress* address) {
return SbSocketConnect(socket_, address);
}

SbSocketError Socket::Bind(const SbSocketAddress* local_address) {
return SbSocketBind(socket_, local_address);
}

SbSocketError Socket::Listen() {
return SbSocketListen(socket_);
}

Socket* Socket::Accept() {
SbSocket accepted_socket = SbSocketAccept(socket_);
if (SbSocketIsValid(accepted_socket)) {
return new Socket(accepted_socket);
}

return NULL;
}

int Socket::ReceiveFrom(char* out_data,
int data_size,
SbSocketAddress* out_source) {
return SbSocketReceiveFrom(socket_, out_data, data_size, out_source);
}

bool Socket::GetLocalAddress(SbSocketAddress* out_address) {
return SbSocketGetLocalAddress(socket_, out_address);
}

bool Socket::SetReuseAddress(bool value) {
return SbSocketSetReuseAddress(socket_, value);
}

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
14 changes: 2 additions & 12 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,11 @@ ExportedSymbols::ExportedSymbols() {
REGISTER_SYMBOL(SbPlayerSetVolume);
REGISTER_SYMBOL(SbPlayerWriteEndOfStream);
REGISTER_SYMBOL(SbPlayerWriteSamples);
REGISTER_SYMBOL(SbSocketAccept);
REGISTER_SYMBOL(SbSocketBind);
REGISTER_SYMBOL(SbSocketConnect);
REGISTER_SYMBOL(SbSocketCreate);
REGISTER_SYMBOL(SbSocketDestroy);
REGISTER_SYMBOL(SbSocketGetInterfaceAddress);
REGISTER_SYMBOL(SbSocketGetLocalAddress);
REGISTER_SYMBOL(SbSocketIsIpv6Supported);
REGISTER_SYMBOL(SbSocketListen);
REGISTER_SYMBOL(SbSocketReceiveFrom);
REGISTER_SYMBOL(SbSocketSetReuseAddress);
REGISTER_SYMBOL(SbSocketWaiterAdd);
// 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
10 changes: 0 additions & 10 deletions starboard/linux/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ static_library("starboard_platform_sources") {
"//starboard/shared/linux/dev_input/dev_input.cc",
"//starboard/shared/linux/dev_input/dev_input.h",
"//starboard/shared/linux/get_home_directory.cc",
"//starboard/shared/linux/socket_get_interface_address.cc",
"//starboard/shared/linux/system_get_random_data.cc",
"//starboard/shared/linux/system_get_stack.cc",
"//starboard/shared/linux/system_get_total_cpu_memory.cc",
Expand Down Expand Up @@ -156,17 +155,8 @@ static_library("starboard_platform_sources") {
"//starboard/shared/posix/memory_mapped_file.h",
"//starboard/shared/posix/page_internal.cc",
"//starboard/shared/posix/set_non_blocking_internal.cc",
"//starboard/shared/posix/socket_accept.cc",
"//starboard/shared/posix/socket_bind.cc",
"//starboard/shared/posix/socket_connect.cc",
"//starboard/shared/posix/socket_create.cc",
"//starboard/shared/posix/socket_destroy.cc",
"//starboard/shared/posix/socket_get_local_address.cc",
"//starboard/shared/posix/socket_internal.cc",
"//starboard/shared/posix/socket_is_ipv6_supported.cc",
"//starboard/shared/posix/socket_listen.cc",
"//starboard/shared/posix/socket_receive_from.cc",
"//starboard/shared/posix/socket_set_reuse_address.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
3 changes: 0 additions & 3 deletions starboard/nplb/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ target(gtest_target_type, "nplb") {
"random_helpers.cc",
"recursive_mutex_test.cc",
"semaphore_test.cc",
"socket_destroy_test.cc",
"socket_get_interface_address_test.cc",
"socket_get_local_address_test.cc",
"socket_helpers.cc",
"socket_waiter_create_test.cc",
"socket_waiter_destroy_test.cc",
Expand Down
Loading
Loading