Skip to content

Commit f193fa1

Browse files
committed
use portable c++23 htons impl
1 parent c6e5af9 commit f193fa1

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

include/unifex/linux/io_uring_context.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,14 @@ class io_uring_context::accept_stream {
13511351
port_t port_;
13521352
safe_file_descriptor fd_;
13531353

1354+
static constexpr std::uint16_t host_to_network(std::uint16_t value) {
1355+
if constexpr (std::endian::native == std::endian::little) {
1356+
return std::byteswap(value);
1357+
} else {
1358+
return value;
1359+
}
1360+
}
1361+
13541362
// TODO should this run on the io_context? If so, why?
13551363
void open_socket() noexcept {
13561364
// both IPv4 and IPv6
@@ -1365,7 +1373,7 @@ class io_uring_context::accept_stream {
13651373
UNIFEX_ASSERT(ret != -1);
13661374

13671375
addr.sin6_family = AF_INET6;
1368-
addr.sin6_port = htons(port_);
1376+
addr.sin6_port = host_to_network(port_);
13691377
addr.sin6_addr = in6addr_any;
13701378
ret = bind(fd_.get(), (const struct sockaddr*)&addr, sizeof(addr));
13711379
UNIFEX_ASSERT(ret != -1);

0 commit comments

Comments
 (0)