Skip to content

Commit

Permalink
print errno name
Browse files Browse the repository at this point in the history
b/321999529

Change-Id: Ie46505ea50979446b1ef128d34b6487a304e2d4b
  • Loading branch information
haozheng-cobalt committed May 2, 2024
1 parent f99b767 commit 643e634
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 5 additions & 4 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 @@ -114,7 +115,7 @@ TEST(PosixSocketSendTest, RainyDaySendToClosedSocket) {
errno == ENOTCONN || // errno on Windows
errno == EINPROGRESS // errno on Evergreen
);
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 +150,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 +202,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
9 changes: 5 additions & 4 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 @@ -117,7 +118,7 @@ TEST(PosixSocketSendtoTest, RainyDaySendToClosedSocket) {
errno == ENOTCONN || // errno on Windows
errno == EINPROGRESS // errno on Evergreen
);
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 +153,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 +201,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 @@ -223,7 +224,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 643e634

Please sign in to comment.