|
|
@ -238,14 +238,14 @@ SockAddrIn TranslateToSockAddrIn(sockaddr input_) {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
u16 TranslatePollEvents(u16 events) {
|
|
|
|
u16 TranslatePollEvents(u32 events) {
|
|
|
|
u16 result = 0;
|
|
|
|
u32 result = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (events & POLL_IN) {
|
|
|
|
if ((events & POLL_IN) != 0) {
|
|
|
|
events &= ~POLL_IN;
|
|
|
|
events &= ~POLL_IN;
|
|
|
|
result |= POLLIN;
|
|
|
|
result |= POLLIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (events & POLL_PRI) {
|
|
|
|
if ((events & POLL_PRI) != 0) {
|
|
|
|
events &= ~POLL_PRI;
|
|
|
|
events &= ~POLL_PRI;
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN32
|
|
|
|
LOG_WARNING(Service, "Winsock doesn't support POLLPRI");
|
|
|
|
LOG_WARNING(Service, "Winsock doesn't support POLLPRI");
|
|
|
@ -253,20 +253,20 @@ u16 TranslatePollEvents(u16 events) {
|
|
|
|
result |= POLL_PRI;
|
|
|
|
result |= POLL_PRI;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (events & POLL_OUT) {
|
|
|
|
if ((events & POLL_OUT) != 0) {
|
|
|
|
events &= ~POLL_OUT;
|
|
|
|
events &= ~POLL_OUT;
|
|
|
|
result |= POLLOUT;
|
|
|
|
result |= POLLOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UNIMPLEMENTED_IF_MSG(events != 0, "Unhandled guest events=0x{:x}", events);
|
|
|
|
UNIMPLEMENTED_IF_MSG(events != 0, "Unhandled guest events=0x{:x}", events);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return static_cast<u16>(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
u16 TranslatePollRevents(u16 revents) {
|
|
|
|
u16 TranslatePollRevents(u32 revents) {
|
|
|
|
u16 result = 0;
|
|
|
|
u32 result = 0;
|
|
|
|
const auto translate = [&result, &revents](int host, unsigned guest) {
|
|
|
|
const auto translate = [&result, &revents](u32 host, u32 guest) {
|
|
|
|
if (revents & host) {
|
|
|
|
if ((revents & host) != 0) {
|
|
|
|
revents &= ~host;
|
|
|
|
revents &= ~host;
|
|
|
|
result |= guest;
|
|
|
|
result |= guest;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -280,7 +280,7 @@ u16 TranslatePollRevents(u16 revents) {
|
|
|
|
|
|
|
|
|
|
|
|
UNIMPLEMENTED_IF_MSG(revents != 0, "Unhandled host revents=0x{:x}", revents);
|
|
|
|
UNIMPLEMENTED_IF_MSG(revents != 0, "Unhandled host revents=0x{:x}", revents);
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return static_cast<u16>(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
@ -350,7 +350,7 @@ std::pair<s32, Errno> Poll(std::vector<PollFD>& pollfds, s32 timeout) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num; ++i) {
|
|
|
|
for (size_t i = 0; i < num; ++i) {
|
|
|
|
pollfds[i].revents = TranslatePollRevents(host_pollfds[i].revents);
|
|
|
|
pollfds[i].revents = TranslatePollRevents(static_cast<u32>(host_pollfds[i].revents));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (result > 0) {
|
|
|
|
if (result > 0) {
|
|
|
@ -408,7 +408,7 @@ std::pair<Socket::AcceptResult, Errno> Socket::Accept() {
|
|
|
|
|
|
|
|
|
|
|
|
Errno Socket::Connect(SockAddrIn addr_in) {
|
|
|
|
Errno Socket::Connect(SockAddrIn addr_in) {
|
|
|
|
const sockaddr host_addr_in = TranslateFromSockAddrIn(addr_in);
|
|
|
|
const sockaddr host_addr_in = TranslateFromSockAddrIn(addr_in);
|
|
|
|
if (connect(fd, &host_addr_in, sizeof(host_addr_in)) != INVALID_SOCKET) {
|
|
|
|
if (connect(fd, &host_addr_in, sizeof(host_addr_in)) != SOCKET_ERROR) {
|
|
|
|
return Errno::SUCCESS;
|
|
|
|
return Errno::SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -503,10 +503,10 @@ std::pair<s32, Errno> Socket::Recv(int flags, std::vector<u8>& message) {
|
|
|
|
ASSERT(flags == 0);
|
|
|
|
ASSERT(flags == 0);
|
|
|
|
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
|
|
|
|
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
|
|
|
|
|
|
|
|
|
|
|
|
const int result =
|
|
|
|
const auto result =
|
|
|
|
recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0);
|
|
|
|
recv(fd, reinterpret_cast<char*>(message.data()), static_cast<int>(message.size()), 0);
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
return {result, Errno::SUCCESS};
|
|
|
|
return {static_cast<s32>(result), Errno::SUCCESS};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (const int ec = LastError()) {
|
|
|
|
switch (const int ec = LastError()) {
|
|
|
@ -531,14 +531,14 @@ std::pair<s32, Errno> Socket::RecvFrom(int flags, std::vector<u8>& message, Sock
|
|
|
|
socklen_t* const p_addrlen = addr ? &addrlen : nullptr;
|
|
|
|
socklen_t* const p_addrlen = addr ? &addrlen : nullptr;
|
|
|
|
sockaddr* const p_addr_in = addr ? &addr_in : nullptr;
|
|
|
|
sockaddr* const p_addr_in = addr ? &addr_in : nullptr;
|
|
|
|
|
|
|
|
|
|
|
|
const int result = recvfrom(fd, reinterpret_cast<char*>(message.data()),
|
|
|
|
const auto result = recvfrom(fd, reinterpret_cast<char*>(message.data()),
|
|
|
|
static_cast<int>(message.size()), 0, p_addr_in, p_addrlen);
|
|
|
|
static_cast<int>(message.size()), 0, p_addr_in, p_addrlen);
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
if (addr) {
|
|
|
|
if (addr) {
|
|
|
|
ASSERT(addrlen == sizeof(addr_in));
|
|
|
|
ASSERT(addrlen == sizeof(addr_in));
|
|
|
|
*addr = TranslateToSockAddrIn(addr_in);
|
|
|
|
*addr = TranslateToSockAddrIn(addr_in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {result, Errno::SUCCESS};
|
|
|
|
return {static_cast<s32>(result), Errno::SUCCESS};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (const int ec = LastError()) {
|
|
|
|
switch (const int ec = LastError()) {
|
|
|
@ -558,10 +558,10 @@ std::pair<s32, Errno> Socket::Send(const std::vector<u8>& message, int flags) {
|
|
|
|
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
|
|
|
|
ASSERT(message.size() < static_cast<size_t>(std::numeric_limits<int>::max()));
|
|
|
|
ASSERT(flags == 0);
|
|
|
|
ASSERT(flags == 0);
|
|
|
|
|
|
|
|
|
|
|
|
const int result = send(fd, reinterpret_cast<const char*>(message.data()),
|
|
|
|
const auto result = send(fd, reinterpret_cast<const char*>(message.data()),
|
|
|
|
static_cast<int>(message.size()), 0);
|
|
|
|
static_cast<int>(message.size()), 0);
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
return {result, Errno::SUCCESS};
|
|
|
|
return {static_cast<s32>(result), Errno::SUCCESS};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const int ec = LastError();
|
|
|
|
const int ec = LastError();
|
|
|
@ -591,10 +591,10 @@ std::pair<s32, Errno> Socket::SendTo(u32 flags, const std::vector<u8>& message,
|
|
|
|
to = &host_addr_in;
|
|
|
|
to = &host_addr_in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const int result = sendto(fd, reinterpret_cast<const char*>(message.data()),
|
|
|
|
const auto result = sendto(fd, reinterpret_cast<const char*>(message.data()),
|
|
|
|
static_cast<int>(message.size()), 0, to, tolen);
|
|
|
|
static_cast<int>(message.size()), 0, to, tolen);
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
if (result != SOCKET_ERROR) {
|
|
|
|
return {result, Errno::SUCCESS};
|
|
|
|
return {static_cast<s32>(result), Errno::SUCCESS};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const int ec = LastError();
|
|
|
|
const int ec = LastError();
|
|
|
|