Return error when shutdown() fails (#2801)

Fix issue reported in #2787.
This commit is contained in:
Marcin Kolny
2023-11-24 13:03:59 +00:00
committed by GitHub
parent 1ba4acd1c7
commit 5f7079f0f5
10 changed files with 88 additions and 66 deletions

View File

@ -46,50 +46,6 @@
CHECK_VALID_FILE_HANDLE((win_dir_stream)->handle); \
} while (0)
static __wasi_errno_t
convert_winsock_error_code(int error_code)
{
switch (error_code) {
case WSASYSNOTREADY:
case WSAEWOULDBLOCK:
return __WASI_EAGAIN;
case WSAVERNOTSUPPORTED:
return __WASI_ENOTSUP;
case WSAEINPROGRESS:
return __WASI_EINPROGRESS;
case WSAEPROCLIM:
return __WASI_EBUSY;
case WSAEFAULT:
return __WASI_EFAULT;
case WSAENETDOWN:
return __WASI_ENETDOWN;
case WSAENOTSOCK:
return __WASI_ENOTSOCK;
case WSAEINTR:
return __WASI_EINTR;
case WSAEAFNOSUPPORT:
return __WASI_EAFNOSUPPORT;
case WSAEMFILE:
return __WASI_ENFILE;
case WSAEINVAL:
return __WASI_EINVAL;
case WSAENOBUFS:
return __WASI_ENOBUFS;
case WSAEPROTONOSUPPORT:
return __WASI_EPROTONOSUPPORT;
case WSAEPROTOTYPE:
return __WASI_EPROTOTYPE;
case WSAESOCKTNOSUPPORT:
return __WASI_ENOTSUP;
case WSAEINVALIDPROCTABLE:
case WSAEINVALIDPROVIDER:
case WSAEPROVIDERFAILEDINIT:
case WSANOTINITIALISED:
default:
return __WASI_EINVAL;
}
}
static __wasi_filetype_t
get_disk_filetype(DWORD attribute)
{
@ -1488,4 +1444,4 @@ os_realpath(const char *path, char *resolved_path)
return NULL;
return resolved_path;
}
}

View File

@ -5,6 +5,8 @@
#include "platform_api_vmcore.h"
#include "platform_api_extension.h"
#include "platform_wasi_types.h"
#include "win_util.h"
/* link with Ws2_32.lib */
#pragma comment(lib, "ws2_32.lib")
@ -238,13 +240,15 @@ os_socket_close(bh_socket_t socket)
return BHT_OK;
}
int
__wasi_errno_t
os_socket_shutdown(bh_socket_t socket)
{
CHECK_VALID_SOCKET_HANDLE(socket);
shutdown(socket->raw.socket, SD_BOTH);
return BHT_OK;
if (shutdown(socket->raw.socket, SD_BOTH) != 0) {
return convert_winsock_error_code(WSAGetLastError());
}
return __WASI_ESUCCESS;
}
int

View File

@ -93,4 +93,54 @@ uwp_print_to_debugger(const char *format, va_list ap)
return ret;
}
#endif
#endif
__wasi_errno_t
convert_winsock_error_code(int error_code)
{
switch (error_code) {
case WSASYSNOTREADY:
case WSAEWOULDBLOCK:
return __WASI_EAGAIN;
case WSAVERNOTSUPPORTED:
return __WASI_ENOTSUP;
case WSAEINPROGRESS:
return __WASI_EINPROGRESS;
case WSAEPROCLIM:
return __WASI_EBUSY;
case WSAEFAULT:
return __WASI_EFAULT;
case WSAENETDOWN:
return __WASI_ENETDOWN;
case WSAENOTSOCK:
return __WASI_ENOTSOCK;
case WSAEINTR:
return __WASI_EINTR;
case WSAEAFNOSUPPORT:
return __WASI_EAFNOSUPPORT;
case WSAEMFILE:
return __WASI_ENFILE;
case WSAEINVAL:
return __WASI_EINVAL;
case WSAENOBUFS:
return __WASI_ENOBUFS;
case WSAEPROTONOSUPPORT:
return __WASI_EPROTONOSUPPORT;
case WSAEPROTOTYPE:
return __WASI_EPROTOTYPE;
case WSAESOCKTNOSUPPORT:
return __WASI_ENOTSUP;
case WSAECONNABORTED:
return __WASI_ECONNABORTED;
case WSAECONNRESET:
return __WASI_ECONNRESET;
case WSAENOTCONN:
return __WASI_ENOTCONN;
case WSAEINVALIDPROCTABLE:
case WSAEINVALIDPROVIDER:
case WSAEPROVIDERFAILEDINIT:
case WSANOTINITIALISED:
default:
return __WASI_EINVAL;
}
}

View File

@ -12,8 +12,12 @@
__wasi_timestamp_t
convert_filetime_to_wasi_timestamp(LPFILETIME filetime);
// Convert a Windows error code to a WASI error code
/* Convert a Windows error code to a WASI error code */
__wasi_errno_t
convert_windows_error_code(DWORD windows_error_code);
/* Convert a Winsock error code to a WASI error code */
__wasi_errno_t
convert_winsock_error_code(int error_code);
#endif /* end of _WIN_UTIL_H */