Merge pull request #4113 from namkazt/soc_recv_from

fix soc service - RecvFrom - SendTo
This commit is contained in:
Weiyi Wang 2018-09-21 12:33:23 -04:00 committed by GitHub
commit d1a576eb14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -545,11 +545,10 @@ void SOC_U::SendTo(Kernel::HLERequestContext& ctx) {
auto input_buff = rp.PopStaticBuffer(); auto input_buff = rp.PopStaticBuffer();
auto dest_addr_buff = rp.PopStaticBuffer(); auto dest_addr_buff = rp.PopStaticBuffer();
CTRSockAddr ctr_dest_addr;
std::memcpy(&ctr_dest_addr, dest_addr_buff.data(), sizeof(ctr_dest_addr));
s32 ret = -1; s32 ret = -1;
if (addr_len > 0) { if (addr_len > 0) {
CTRSockAddr ctr_dest_addr;
std::memcpy(&ctr_dest_addr, dest_addr_buff.data(), sizeof(ctr_dest_addr));
sockaddr dest_addr = CTRSockAddr::ToPlatform(ctr_dest_addr); sockaddr dest_addr = CTRSockAddr::ToPlatform(ctr_dest_addr);
ret = ::sendto(socket_handle, reinterpret_cast<const char*>(input_buff.data()), len, flags, ret = ::sendto(socket_handle, reinterpret_cast<const char*>(input_buff.data()), len, flags,
&dest_addr, sizeof(dest_addr)); &dest_addr, sizeof(dest_addr));
@ -624,13 +623,21 @@ void SOC_U::RecvFrom(Kernel::HLERequestContext& ctx) {
std::vector<u8> addr_buff(sizeof(ctr_src_addr)); std::vector<u8> addr_buff(sizeof(ctr_src_addr));
sockaddr src_addr; sockaddr src_addr;
socklen_t src_addr_len = sizeof(src_addr); socklen_t src_addr_len = sizeof(src_addr);
s32 ret = ::recvfrom(socket_handle, reinterpret_cast<char*>(output_buff.data()), len, flags,
&src_addr, &src_addr_len);
s32 ret = -1;
if (addr_len > 0) {
// Only get src adr if input adr available
ret = ::recvfrom(socket_handle, reinterpret_cast<char*>(output_buff.data()), len, flags,
&src_addr, &src_addr_len);
if (ret >= 0 && src_addr_len > 0) { if (ret >= 0 && src_addr_len > 0) {
ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); ctr_src_addr = CTRSockAddr::FromPlatform(src_addr);
std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr));
} }
} else {
ret = ::recvfrom(socket_handle, reinterpret_cast<char*>(output_buff.data()), len, flags,
NULL, 0);
addr_buff.resize(0);
}
s32 total_received = ret; s32 total_received = ret;
if (ret == SOCKET_ERROR_VALUE) { if (ret == SOCKET_ERROR_VALUE) {