MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / sockRecv

Method sockRecv

lib/host/wasi/inode-win.cpp:1710–1750  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1708}
1709
1710WasiExpect<void> INode::sockRecv(Span<Span<uint8_t>> RiData,
1711 __wasi_riflags_t RiFlags, __wasi_size_t &NRead,
1712 __wasi_roflags_t &RoFlags) const noexcept {
1713 EXPECTED_TRY(detail::ensureWSAStartup());
1714
1715 int SysRiFlags = 0;
1716 if (RiFlags & __WASI_RIFLAGS_RECV_PEEK) {
1717 SysRiFlags |= MSG_PEEK;
1718 }
1719#if NTDDI_VERSION >= NTDDI_WS03
1720 if (RiFlags & __WASI_RIFLAGS_RECV_WAITALL) {
1721 SysRiFlags |= MSG_WAITALL;
1722 }
1723#endif
1724
1725 std::size_t TmpBufSize = 0;
1726 for (auto &IOV : RiData) {
1727 TmpBufSize += IOV.size();
1728 }
1729
1730 std::vector<uint8_t> TmpBuf(TmpBufSize, 0);
1731
1732 if (auto Res = recv(Socket, reinterpret_cast<char *>(TmpBuf.data()),
1733 static_cast<int>(TmpBufSize), SysRiFlags);
1734 unlikely(Res == SOCKET_ERROR_)) {
1735 return WasiUnexpect(detail::fromWSALastError());
1736 } else {
1737 NRead = static_cast<__wasi_size_t>(Res);
1738 }
1739
1740 RoFlags = static_cast<__wasi_roflags_t>(0);
1741
1742 size_t BeginIdx = 0;
1743 for (auto &IOV : RiData) {
1744 std::copy(TmpBuf.data() + BeginIdx, TmpBuf.data() + BeginIdx + IOV.size(),
1745 IOV.begin());
1746 BeginIdx += IOV.size();
1747 }
1748
1749 return {};
1750}
1751
1752WasiExpect<void> INode::sockRecvFrom(Span<Span<uint8_t>> RiData,
1753 __wasi_riflags_t RiFlags,

Callers 1

bodyMethod · 0.45

Calls 8

ensureWSAStartupFunction · 0.85
unlikelyFunction · 0.85
WasiUnexpectFunction · 0.85
fromWSALastErrorFunction · 0.85
EXPECTED_TRYFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected