Skip to content

Commit

Permalink
nsysnet: Add support for SO_BIO and handle SO_ENOTCONN
Browse files Browse the repository at this point in the history
  • Loading branch information
Exzap committed Dec 13, 2023
1 parent d2ba4e6 commit bc57c73
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Cafe/OS/libs/nsysnet/nsysnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define WU_SO_RCVBUF 0x1002
#define WU_SO_LASTERROR 0x1007
#define WU_SO_NBIO 0x1014
#define WU_SO_BIO 0x1015
#define WU_SO_NONBLOCK 0x1016

#define WU_TCP_NODELAY 0x2004
Expand All @@ -53,6 +54,7 @@
#define WU_SO_SUCCESS 0x0000
#define WU_SO_EWOULDBLOCK 0x0006
#define WU_SO_ECONNRESET 0x0008
#define WU_SO_ENOTCONN 0x0009
#define WU_SO_EINVAL 0x000B
#define WU_SO_EINPROGRESS 0x0016
#define WU_SO_EAFNOSUPPORT 0x0021
Expand Down Expand Up @@ -148,16 +150,19 @@ sint32 _translateError(sint32 returnCode, sint32 wsaError, sint32 mode = _ERROR_
case WSAESHUTDOWN:
_setSockError(WU_SO_ESHUTDOWN);
break;
case WSAENOTCONN:
_setSockError(WU_SO_ENOTCONN);
break;
default:
cemuLog_logDebug(LogType::Force, "Unhandled wsaError {}\n", wsaError);
cemuLog_logDebug(LogType::Force, "Unhandled wsaError {}", wsaError);
_setSockError(99999); // unhandled error
}
return -1;
}

void nsysnetExport_socketlasterr(PPCInterpreter_t* hCPU)
{
cemuLog_log(LogType::Socket, "socketlasterr() -> {}", _getSockError());
cemuLog_logDebug(LogType::Socket, "socketlasterr() -> {}", _getSockError());
osLib_returnFromFunction(hCPU, _getSockError());
}

Expand Down Expand Up @@ -485,9 +490,9 @@ void nsysnetExport_setsockopt(PPCInterpreter_t* hCPU)
if (r != 0)
cemu_assert_suspicious();
}
else if (optname == WU_SO_NBIO)
else if (optname == WU_SO_NBIO || optname == WU_SO_BIO)
{
// similar to WU_SO_NONBLOCK but always sets non-blocking mode regardless of option value
// similar to WU_SO_NONBLOCK but always sets blocking (_BIO) or non-blocking (_NBIO) mode regardless of option value
if (optlen == 4)
{
sint32 optvalLE = _swapEndianU32(*(uint32*)optval);
Expand All @@ -498,9 +503,10 @@ void nsysnetExport_setsockopt(PPCInterpreter_t* hCPU)
}
else
cemu_assert_suspicious();
u_long mode = 1;
bool setNonBlocking = optname == WU_SO_NBIO;
u_long mode = setNonBlocking ? 1 : 0;
_socket_nonblock(vs->s, mode);
vs->isNonBlocking = true;
vs->isNonBlocking = setNonBlocking;
}
else if (optname == WU_SO_NONBLOCK)
{
Expand Down

1 comment on commit bc57c73

@hummeltech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be missing within the #if BOOST_OS_UNIX block:

#define WSAENOTCONN ENOTCONN

See below for build pipeline failures:

Please sign in to comment.