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

Cherry pick PR #3138: print errno name #3401

Merged
merged 1 commit into from
Jun 13, 2024
Merged
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
14 changes: 8 additions & 6 deletions starboard/nplb/posix_compliance/posix_socket_send_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include "starboard/nplb/posix_compliance/posix_socket_helpers.h"
#include "starboard/thread.h"
Expand Down Expand Up @@ -78,7 +79,7 @@ TEST(PosixSocketSendTest, RainyDayUnconnectedSocket) {

EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE ||
errno == ENOTCONN);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);

EXPECT_TRUE(close(socket_fd) == 0);
}
Expand Down Expand Up @@ -111,10 +112,11 @@ TEST(PosixSocketSendTest, RainyDaySendToClosedSocket) {
EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0);

EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE ||
errno == ENOTCONN || // errno on Windows
errno == EINPROGRESS // errno on Evergreen
errno == ENOTCONN || // errno on Windows
errno == EINPROGRESS || // errno on Evergreen
errno == ENETUNREACH // errno on raspi
);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);

// Clean up the server socket.
EXPECT_TRUE(close(server_socket_fd) == 0);
Expand Down Expand Up @@ -149,7 +151,7 @@ TEST(PosixSocketSendTest, RainyDaySendToSocketUntilBlocking) {
// If we didn't get a socket, it should be pending.
EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN ||
errno == EWOULDBLOCK);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);
break;
}

Expand Down Expand Up @@ -201,7 +203,7 @@ TEST(PosixSocketSendTest, RainyDaySendToSocketConnectionReset) {
if (result < 0) {
EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE ||
errno == ECONNABORTED);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);
break;
}

Expand Down
14 changes: 8 additions & 6 deletions starboard/nplb/posix_compliance/posix_socket_sendto_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>

#include "starboard/nplb/posix_compliance/posix_socket_helpers.h"
Expand Down Expand Up @@ -81,7 +82,7 @@ TEST(PosixSocketSendtoTest, RainyDayUnconnectedSocket) {

EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE ||
errno == ENOTCONN);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);

EXPECT_TRUE(close(socket_fd) == 0);
}
Expand Down Expand Up @@ -114,10 +115,11 @@ TEST(PosixSocketSendtoTest, RainyDaySendToClosedSocket) {
EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0);

EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE ||
errno == ENOTCONN || // errno on Windows
errno == EINPROGRESS // errno on Evergreen
errno == ENOTCONN || // errno on Windows
errno == EINPROGRESS || // errno on Evergreen
errno == ENETUNREACH // errno on raspi
);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);

// Clean up the server socket.
EXPECT_TRUE(close(server_socket_fd) == 0);
Expand Down Expand Up @@ -152,7 +154,7 @@ TEST(PosixSocketSendtoTest, RainyDaySendToSocketUntilBlocking) {
// If we didn't get a socket, it should be pending.
EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN ||
errno == EWOULDBLOCK);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);
break;
}

Expand Down Expand Up @@ -200,7 +202,7 @@ TEST(PosixSocketSendtoTest, RainyDaySendToSocketConnectionReset) {
if (result < 0) {
EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE ||
errno == ECONNABORTED);
SB_DLOG(INFO) << "Failed to send, errno = " << errno;
SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno);
break;
}

Expand Down
5 changes: 3 additions & 2 deletions starboard/shared/win32/posix_emu/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
// We specifically do not include <sys/socket.h> since the define causes a loop

#include <fcntl.h>
#include <io.h> // Needed for file-specific `_close`.
#include <io.h> // Needed for file-specific `_close`.
#include <string.h>
#include <unistd.h> // Our version that declares generic `close`.
#include <winsock2.h>
#undef NO_ERROR // http://b/302733082#comment15
Expand Down Expand Up @@ -225,7 +226,7 @@ static void set_errno() {
}

_set_errno(sockError);
SB_DLOG(INFO) << "Encounter socket error: " << sockError;
SB_DLOG(INFO) << "Encounter socket error: " << strerror(sockError);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
Loading