[XAM/Net] Added unified method of returning WSA error codes

This commit is contained in:
Gliniak 2021-11-17 13:05:24 +01:00
parent 0b90d5edf9
commit d4e5ecb93b
3 changed files with 19 additions and 20 deletions

View File

@ -633,8 +633,7 @@ dword_result_t NetDll_socket_entry(dword_t caller, dword_t af, dword_t type,
if (XFAILED(result)) { if (XFAILED(result)) {
socket->Release(); socket->Release();
uint32_t error = xboxkrnl::xeRtlNtStatusToDosError(result); XThread::SetLastError(socket->GetLastWSAError());
XThread::SetLastError(error);
return -1; return -1;
} }
@ -671,12 +670,7 @@ int_result_t NetDll_shutdown_entry(dword_t caller, dword_t socket_handle,
auto ret = socket->Shutdown(how); auto ret = socket->Shutdown(how);
if (ret == -1) { if (ret == -1) {
#ifdef XE_PLATFORM_WIN32 XThread::SetLastError(socket->GetLastWSAError());
uint32_t error_code = WSAGetLastError();
XThread::SetLastError(error_code);
#else
XThread::SetLastError(0x0);
#endif
} }
return ret; return ret;
} }
@ -710,7 +704,7 @@ dword_result_t NetDll_ioctlsocket_entry(dword_t caller, dword_t socket_handle,
X_STATUS status = socket->IOControl(cmd, arg_ptr); X_STATUS status = socket->IOControl(cmd, arg_ptr);
if (XFAILED(status)) { if (XFAILED(status)) {
XThread::SetLastError(xboxkrnl::xeRtlNtStatusToDosError(status)); XThread::SetLastError(socket->GetLastWSAError());
return -1; return -1;
} }
@ -733,7 +727,7 @@ dword_result_t NetDll_bind_entry(dword_t caller, dword_t socket_handle,
N_XSOCKADDR_IN native_name(name); N_XSOCKADDR_IN native_name(name);
X_STATUS status = socket->Bind(&native_name, namelen); X_STATUS status = socket->Bind(&native_name, namelen);
if (XFAILED(status)) { if (XFAILED(status)) {
XThread::SetLastError(xboxkrnl::xeRtlNtStatusToDosError(status)); XThread::SetLastError(socket->GetLastWSAError());
return -1; return -1;
} }
@ -755,7 +749,7 @@ dword_result_t NetDll_connect_entry(dword_t caller, dword_t socket_handle,
N_XSOCKADDR native_name(name); N_XSOCKADDR native_name(name);
X_STATUS status = socket->Connect(&native_name, namelen); X_STATUS status = socket->Connect(&native_name, namelen);
if (XFAILED(status)) { if (XFAILED(status)) {
XThread::SetLastError(xboxkrnl::xeRtlNtStatusToDosError(status)); XThread::SetLastError(socket->GetLastWSAError());
return -1; return -1;
} }
@ -775,7 +769,7 @@ dword_result_t NetDll_listen_entry(dword_t caller, dword_t socket_handle,
X_STATUS status = socket->Listen(backlog); X_STATUS status = socket->Listen(backlog);
if (XFAILED(status)) { if (XFAILED(status)) {
XThread::SetLastError(xboxkrnl::xeRtlNtStatusToDosError(status)); XThread::SetLastError(socket->GetLastWSAError());
return -1; return -1;
} }
@ -969,13 +963,7 @@ dword_result_t NetDll_recvfrom_entry(dword_t caller, dword_t socket_handle,
} }
if (ret == -1) { if (ret == -1) {
// TODO: Better way of getting the error code XThread::SetLastError(socket->GetLastWSAError());
#ifdef XE_PLATFORM_WIN32
uint32_t error_code = WSAGetLastError();
XThread::SetLastError(error_code);
#else
XThread::SetLastError(0x0);
#endif
} }
return ret; return ret;
@ -1045,7 +1033,7 @@ dword_result_t NetDll_getsockname_entry(dword_t caller, dword_t socket_handle,
X_STATUS status = socket->GetSockName(buf_ptr, &buffer_len); X_STATUS status = socket->GetSockName(buf_ptr, &buffer_len);
if (XFAILED(status)) { if (XFAILED(status)) {
XThread::SetLastError(xboxkrnl::xeRtlNtStatusToDosError(status)); XThread::SetLastError(socket->GetLastWSAError());
return -1; return -1;
} }

View File

@ -269,5 +269,14 @@ X_STATUS XSocket::GetSockName(uint8_t* buf, int* buf_len) {
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }
uint32_t XSocket::GetLastWSAError() const {
// Todo(Gliniak): Provide error mapping table
// Xbox error codes might not match with what we receive from OS
#ifdef XE_PLATFORM_WIN32
return WSAGetLastError();
#endif
return errno;
}
} // namespace kernel } // namespace kernel
} // namespace xe } // namespace xe

View File

@ -118,6 +118,8 @@ class XSocket : public XObject {
int SendTo(uint8_t* buf, uint32_t buf_len, uint32_t flags, N_XSOCKADDR_IN* to, int SendTo(uint8_t* buf, uint32_t buf_len, uint32_t flags, N_XSOCKADDR_IN* to,
uint32_t to_len); uint32_t to_len);
uint32_t GetLastWSAError() const;
struct packet { struct packet {
// These values are in network byte order. // These values are in network byte order.
xe::be<uint16_t> src_port; xe::be<uint16_t> src_port;