Merge pull request #4230 from MarcZX100/codex/carry-socket-flags-4028
fix(libkernel): accept socket type flags
This commit is contained in:
commit
a3b3cec05e
|
|
@ -493,9 +493,11 @@ int APS5_VABI getsockopt_nid_postfix(int descriptor, int level, int option,
|
|||
return 0;
|
||||
}
|
||||
int APS5_VABI socket_nid_postfix(int family, int type, int protocol) {
|
||||
const bool nonblocking = (type & GuestNonBlocking) != 0;
|
||||
const int plainType = type & ~(GuestCloseOnExec | GuestNonBlocking);
|
||||
if (family != 2 && family != 28) return Fail(47);
|
||||
const int nativeType = type == 1 ? SOCK_STREAM : type == 2 ? SOCK_DGRAM : -1;
|
||||
const int expectedProtocol = type == 1 ? 6 : 17;
|
||||
const int nativeType = plainType == 1 ? SOCK_STREAM : plainType == 2 ? SOCK_DGRAM : -1;
|
||||
const int expectedProtocol = plainType == 1 ? 6 : 17;
|
||||
if (nativeType == -1 || (protocol != 0 && protocol != expectedProtocol)) return Fail(43);
|
||||
#ifdef _WIN32
|
||||
static const int startup = [] { WSADATA data{}; return WSAStartup(MAKEWORD(2, 2), &data); }();
|
||||
|
|
@ -503,10 +505,11 @@ int APS5_VABI socket_nid_postfix(int family, int type, int protocol) {
|
|||
#endif
|
||||
const auto native = ::socket(family == 2 ? AF_INET : AF_INET6, nativeType, protocol);
|
||||
if (native == Invalid) return Fail(NativeError());
|
||||
Socket guard(native, family, type);
|
||||
Socket guard(native, family, plainType);
|
||||
try {
|
||||
auto socket = std::make_shared<Socket>(native, family, type);
|
||||
auto socket = std::make_shared<Socket>(native, family, plainType);
|
||||
guard.value = Invalid;
|
||||
if (nonblocking && SetNonBlocking(*socket)) return -1;
|
||||
std::lock_guard lock(socketsMutex);
|
||||
if (nextDescriptor == INT_MAX) return Fail(24);
|
||||
const int descriptor = nextDescriptor++;
|
||||
|
|
|
|||
|
|
@ -163,4 +163,14 @@ int main() {
|
|||
const int stream = socket_nid_postfix(2, 1, 0);
|
||||
Require(stream >= 0);
|
||||
Require(close_nid_postfix(stream) == 0);
|
||||
const int nonblocking = socket_nid_postfix(2, 2 | 0x20000000, 0);
|
||||
Require(nonblocking >= 0 && fcntl_nid_postfix(nonblocking, 3) == 6);
|
||||
std::array<unsigned char, 16> nonblockingAddress{16, 2, 0, 0, 127, 0, 0, 1};
|
||||
Require(bind_nid_postfix(nonblocking, nonblockingAddress.data(), nonblockingAddress.size()) == 0);
|
||||
Require(recvfrom_nid_postfix(nonblocking, buffer, sizeof(buffer), 0, nullptr, nullptr) == -1 && *__error_nid_postfix() == 35);
|
||||
Require(close_nid_postfix(nonblocking) == 0);
|
||||
const int closeOnExec = socket_nid_postfix(2, 1 | 0x10000000, 6);
|
||||
Require(closeOnExec >= 0 && fcntl_nid_postfix(closeOnExec, 3) == 2);
|
||||
Require(close_nid_postfix(closeOnExec) == 0);
|
||||
Require(socket_nid_postfix(2, 0x20000000, 0) == -1 && *__error_nid_postfix() == 43);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue