|
43 | 43 | namespace NUClear { |
44 | 44 | namespace network { |
45 | 45 |
|
| 46 | +namespace { |
| 47 | + |
| 48 | + iovec make_iovec(void* base, std::size_t len) { |
| 49 | +#ifdef _WIN32 |
| 50 | + iovec iov{}; |
| 51 | + iov.buf = reinterpret_cast<CHAR*>(base); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) |
| 52 | + iov.len = static_cast<ULONG>(len); |
| 53 | + return iov; |
| 54 | +#else |
| 55 | + iovec iov{}; |
| 56 | + iov.iov_base = base; |
| 57 | + iov.iov_len = len; |
| 58 | + return iov; |
| 59 | +#endif |
| 60 | + } |
| 61 | + |
| 62 | +} // namespace |
| 63 | + |
46 | 64 | const std::chrono::milliseconds NUClearNet::ANNOUNCE_INTERVAL(500); // NOLINT(cert-err58-cpp) |
47 | 65 |
|
48 | 66 | NUClearNet::NUClearNet() |
@@ -268,11 +286,10 @@ namespace network { |
268 | 286 | header.flags = req.flags; |
269 | 287 | header.hash = req.hash; |
270 | 288 |
|
271 | | - std::array<iovec, 2> iov{}; |
272 | | - iov[0].iov_base = reinterpret_cast<char*>(&header); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) |
273 | | - iov[0].iov_len = static_cast<decltype(iov[0].iov_len)>(sizeof(DataPacket) - 1); |
274 | | - iov[1].iov_base = const_cast<char*>(reinterpret_cast<const char*>(req.data.data())); // NOLINT(cppcoreguidelines-pro-type-const-cast,cppcoreguidelines-pro-type-reinterpret-cast) |
275 | | - iov[1].iov_len = static_cast<decltype(iov[1].iov_len)>(req.data.size()); |
| 289 | + std::array<iovec, 2> iov{ |
| 290 | + make_iovec(reinterpret_cast<void*>(&header), sizeof(DataPacket) - 1), // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) |
| 291 | + make_iovec(const_cast<void*>(static_cast<const void*>(req.data.data())), req.data.size()), // NOLINT(cppcoreguidelines-pro-type-const-cast) |
| 292 | + }; |
276 | 293 |
|
277 | 294 | send_iov(data_fd, req.target, iov.data(), static_cast<int>(iov.size())); |
278 | 295 | } |
@@ -321,11 +338,10 @@ namespace network { |
321 | 338 | const std::size_t offset = static_cast<std::size_t>(i) * packet_mtu; |
322 | 339 | const std::size_t frag_len = std::min(static_cast<std::size_t>(packet_mtu), length - offset); |
323 | 340 |
|
324 | | - std::array<iovec, 2> iov{}; |
325 | | - iov[0].iov_base = reinterpret_cast<char*>(&header); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) |
326 | | - iov[0].iov_len = static_cast<decltype(iov[0].iov_len)>(sizeof(DataPacket) - 1); |
327 | | - iov[1].iov_base = const_cast<char*>(reinterpret_cast<const char*>(payload + offset)); // NOLINT(cppcoreguidelines-pro-type-const-cast,cppcoreguidelines-pro-type-reinterpret-cast) |
328 | | - iov[1].iov_len = static_cast<decltype(iov[1].iov_len)>(frag_len); |
| 341 | + std::array<iovec, 2> iov{ |
| 342 | + make_iovec(reinterpret_cast<void*>(&header), sizeof(DataPacket) - 1), // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) |
| 343 | + make_iovec(const_cast<void*>(static_cast<const void*>(payload + offset)), frag_len), // NOLINT(cppcoreguidelines-pro-type-const-cast) |
| 344 | + }; |
329 | 345 |
|
330 | 346 | send_iov(data_fd, dest, iov.data(), static_cast<int>(iov.size())); |
331 | 347 | } |
@@ -631,9 +647,15 @@ namespace network { |
631 | 647 | msg.msg_iovlen = static_cast<decltype(msg.msg_iovlen)>(iovcnt); |
632 | 648 | msg.msg_control = nullptr; |
633 | 649 | msg.msg_controllen = 0; |
634 | | - msg.msg_flags = 0; |
| 650 | +#ifndef _WIN32 |
| 651 | + msg.msg_flags = 0; |
| 652 | +#endif |
635 | 653 |
|
| 654 | +#ifdef _WIN32 |
| 655 | + NUClear::sendmsg(fd, &msg, 0); |
| 656 | +#else |
636 | 657 | ::sendmsg(fd, &msg, 0); |
| 658 | +#endif |
637 | 659 | } |
638 | 660 |
|
639 | 661 | } // namespace network |
|
0 commit comments