Skip to content

Commit

Permalink
Cherry pick PR #3138: print errno name (#3401)
Browse files Browse the repository at this point in the history
Refer to the original PR: #3138

b/321999529

Change-Id: Ie46505ea50979446b1ef128d34b6487a304e2d4b

Co-authored-by: Hao <[email protected]>
  • Loading branch information
1 parent c1cc4f1 commit 8fa928a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
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

0 comments on commit 8fa928a

Please sign in to comment.