Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
Change-Id: Id482f86a97edabd86ba7d7a5e8a98e7ade758b75
  • Loading branch information
madhurajayaraman committed Sep 25, 2024
1 parent f37c169 commit a99f755
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 309 deletions.
90 changes: 0 additions & 90 deletions starboard/shared/libevent/socket_waiter_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -57,76 +47,13 @@ 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()
: thread_(pthread_self()),
base_(event_base_new()),
waiting_(false),
woken_up_(false) {
#if USE_POSIX_PIPE
int fds[2];
int result = pipe(fds);
SB_DCHECK(result == 0);
Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -547,5 +459,3 @@ SbSocketWaiterPrivate::Waitee* SbSocketWaiterPrivate::RemoveWaitee(
sb_waitees_.erase(it);
return result;
}

#undef USE_POSIX_PIPE
162 changes: 0 additions & 162 deletions starboard/shared/starboard/net_args.cc

This file was deleted.

57 changes: 0 additions & 57 deletions starboard/shared/starboard/net_args.h

This file was deleted.

0 comments on commit a99f755

Please sign in to comment.