diff --git a/starboard/nplb/posix_compliance/posix_socket_send_test.cc b/starboard/nplb/posix_compliance/posix_socket_send_test.cc index 3383f0847664..59cad674bfd9 100644 --- a/starboard/nplb/posix_compliance/posix_socket_send_test.cc +++ b/starboard/nplb/posix_compliance/posix_socket_send_test.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include "starboard/nplb/posix_compliance/posix_socket_helpers.h" #include "starboard/thread.h" @@ -76,8 +77,14 @@ TEST(PosixSocketSendTest, RainyDayUnconnectedSocket) { ssize_t bytes_written = send(socket_fd, buf, sizeof(buf), kSendFlags); EXPECT_FALSE(bytes_written >= 0); +<<<<<<< HEAD // TODO: check errno: EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || // errno == EPIPE); +======= + EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || + errno == ENOTCONN); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) EXPECT_TRUE(close(socket_fd) == 0); } @@ -109,8 +116,17 @@ TEST(PosixSocketSendTest, RainyDaySendToClosedSocket) { void* thread_result; EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0); +<<<<<<< HEAD // TODO: errno: EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno // == EPIPE); +======= + EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || + errno == ENOTCONN || // errno on Windows + errno == EINPROGRESS || // errno on Evergreen + errno == ENETUNREACH // errno on raspi + ); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) // Clean up the server socket. EXPECT_TRUE(close(server_socket_fd) == 0); @@ -143,9 +159,15 @@ TEST(PosixSocketSendTest, RainyDaySendToSocketUntilBlocking) { if (result < 0) { // If we didn't get a socket, it should be pending. +<<<<<<< HEAD // TODO: export errno // EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN || errno == // EWOULDBLOCK); +======= + EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN || + errno == EWOULDBLOCK); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) break; } @@ -191,10 +213,16 @@ TEST(PosixSocketSendTest, RainyDaySendToSocketConnectionReset) { result = send(client_socket_fd, buff, sizeof(buff), kSendFlags); if (result < 0) { +<<<<<<< HEAD // TODO: errno: // EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == // EPIPE); SB_DLOG(INFO) << "Failed to send, errno = " << errno; +======= + EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || + errno == ECONNABORTED); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) break; } diff --git a/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc b/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc index b320b7262bdb..9fc30997c8c2 100644 --- a/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc +++ b/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include "starboard/nplb/posix_compliance/posix_socket_helpers.h" @@ -79,8 +80,14 @@ TEST(PosixSocketSendtoTest, RainyDayUnconnectedSocket) { sendto(socket_fd, buf, sizeof(buf), kSendFlags, NULL, 0); EXPECT_FALSE(bytes_written >= 0); +<<<<<<< HEAD // TODO: check errno: EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || // errno == EPIPE); +======= + EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || + errno == ENOTCONN); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) EXPECT_TRUE(close(socket_fd) == 0); } @@ -112,8 +119,17 @@ TEST(PosixSocketSendtoTest, RainyDaySendToClosedSocket) { void* thread_result; EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0); +<<<<<<< HEAD // TODO: errno: EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno // == EPIPE); +======= + EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || + errno == ENOTCONN || // errno on Windows + errno == EINPROGRESS || // errno on Evergreen + errno == ENETUNREACH // errno on raspi + ); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) // Clean up the server socket. EXPECT_TRUE(close(server_socket_fd) == 0); @@ -146,9 +162,15 @@ TEST(PosixSocketSendtoTest, RainyDaySendToSocketUntilBlocking) { if (result < 0) { // If we didn't get a socket, it should be pending. +<<<<<<< HEAD // TODO: export errno // EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN || errno == // EWOULDBLOCK); +======= + EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN || + errno == EWOULDBLOCK); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) break; } @@ -194,10 +216,16 @@ TEST(PosixSocketSendtoTest, RainyDaySendToSocketConnectionReset) { result = sendto(client_socket_fd, buff, sizeof(buff), kSendFlags, NULL, 0); if (result < 0) { +<<<<<<< HEAD // TODO: errno: // EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == // EPIPE); SB_DLOG(INFO) << "Failed to send, errno = " << errno; +======= + EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || + errno == ECONNABORTED); + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); +>>>>>>> 48244d436bb (print errno name (#3138)) break; } diff --git a/starboard/shared/win32/posix_emu/socket.cc b/starboard/shared/win32/posix_emu/socket.cc index 4d57a04e95b4..720f88a41f05 100644 --- a/starboard/shared/win32/posix_emu/socket.cc +++ b/starboard/shared/win32/posix_emu/socket.cc @@ -15,7 +15,8 @@ // We specifically do not include since the define causes a loop #include -#include // Needed for file-specific `_close`. +#include // Needed for file-specific `_close`. +#include #include // Our version that declares generic `close`. #include #undef NO_ERROR // http://b/302733082#comment15 @@ -91,6 +92,143 @@ static FileOrSocket handle_db_get(int fd, bool erase) { return handle; } +<<<<<<< HEAD +======= +// WSAGetLastError should be called immediately to retrieve the extended error +// code for the failing function call. +// https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2 +static void set_errno() { + int winsockError = WSAGetLastError(); + int sockError = 0; + + // The error codes returned by Windows Sockets are similar to UNIX socket + // error code constants, but the constants are all prefixed with WSA. So in + // Winsock applications the WSAEWOULDBLOCK error code would be returned, while + // in UNIX applications the EWOULDBLOCK error code would be returned. The + // errno values in a WIN32 are a subset of the values for errno in UNIX + // systems. + switch (winsockError) { + case WSAEINTR: // Interrupted function call + sockError = EINTR; + break; + case WSAEBADF: // WSAEBADF + sockError = EBADF; + break; + case WSAEACCES: // WSAEACCES + sockError = EACCES; + break; + case WSAEFAULT: // Bad address + sockError = EFAULT; + break; + case WSAEINVAL: // Invalid argument + sockError = EINVAL; + break; + case WSAEMFILE: // Too many open files + sockError = EMFILE; + break; + case WSAEWOULDBLOCK: // Operation would block + sockError = EWOULDBLOCK; + break; + case WSAEINPROGRESS: // Operation now in progress + sockError = EINPROGRESS; + break; + case WSAEALREADY: // Operation already in progress + sockError = EALREADY; + break; + case WSAENOTSOCK: // Socket operation on non-socket + sockError = ENOTSOCK; + break; + case WSAEDESTADDRREQ: // Destination address required + sockError = EDESTADDRREQ; + break; + case WSAEMSGSIZE: // Message too long + sockError = EMSGSIZE; + break; + case WSAEPROTOTYPE: // Protocol wrong type for socket + sockError = EPROTOTYPE; + break; + case WSAENOPROTOOPT: // Bad protocol option + sockError = ENOPROTOOPT; + break; + case WSAEPROTONOSUPPORT: // Protocol not supported + sockError = EPROTONOSUPPORT; + break; + case WSAEOPNOTSUPP: // Operation not supported + sockError = EOPNOTSUPP; + break; + case WSAEAFNOSUPPORT: // Address family not supported by protocol family + sockError = EAFNOSUPPORT; + break; + case WSAEADDRINUSE: // Address already in use + sockError = EADDRINUSE; + break; + case WSAEADDRNOTAVAIL: // Cannot assign requested address + sockError = EADDRNOTAVAIL; + break; + case WSAENETDOWN: // Network is down + sockError = ENETDOWN; + break; + case WSAENETUNREACH: // Network is unreachable + sockError = ENETUNREACH; + break; + case WSAENETRESET: // Network dropped connection on reset + sockError = ENETRESET; + break; + case WSAECONNABORTED: // Software caused connection abort + sockError = ECONNABORTED; + break; + case WSAECONNRESET: // Connection reset by peer + sockError = ECONNRESET; + break; + case WSAENOBUFS: // No buffer space available + sockError = ENOBUFS; + break; + case WSAEISCONN: // Socket is already connected + sockError = EISCONN; + break; + case WSAENOTCONN: // Socket is not connected + sockError = ENOTCONN; + break; + case WSAETIMEDOUT: // Connection timed out + sockError = ETIMEDOUT; + break; + case WSAECONNREFUSED: // Connection refused + sockError = ECONNREFUSED; + break; + case WSAELOOP: // WSAELOOP + sockError = ELOOP; + break; + case WSAENAMETOOLONG: // WSAENAMETOOLONG + sockError = ENAMETOOLONG; + break; + case WSAEHOSTUNREACH: // No route to host + sockError = EHOSTUNREACH; + break; + case WSAENOTEMPTY: // WSAENOTEMPTY + sockError = ENOTEMPTY; + break; + case WSAHOST_NOT_FOUND: // Host not found + sockError = HOST_NOT_FOUND; + break; + case WSATRY_AGAIN: // Non-authoritative host not found + sockError = TRY_AGAIN; + break; + case WSANO_RECOVERY: // This is a non-recoverable error + sockError = NO_RECOVERY; + break; + case WSANO_DATA: // Valid name, no data record of requested type + sockError = NO_DATA; + break; + default: + SB_DLOG(WARNING) << "Unknown socket error."; + break; + } + + _set_errno(sockError); + SB_DLOG(INFO) << "Encounter socket error: " << strerror(sockError); +} + +>>>>>>> 48244d436bb (print errno name (#3138)) /////////////////////////////////////////////////////////////////////////////// // Implementations below exposed externally in pure C for emulation. ///////////////////////////////////////////////////////////////////////////////