| 669 | } |
| 670 | |
| 671 | static int net_set_blocking_impl(NETSOCKET sock, bool blocking) |
| 672 | { |
| 673 | unsigned long mode = blocking ? 0 : 1; |
| 674 | const char *mode_str = blocking ? "blocking" : "non-blocking"; |
| 675 | int sockets[] = {sock->ipv4sock, sock->ipv6sock}; |
| 676 | const char *socket_str[] = {"IPv4", "IPv6"}; |
| 677 | |
| 678 | for(size_t i = 0; i < std::size(sockets); ++i) |
| 679 | { |
| 680 | if(sockets[i] >= 0) |
| 681 | { |
| 682 | #if defined(CONF_FAMILY_WINDOWS) |
| 683 | if(ioctlsocket(sockets[i], FIONBIO, (unsigned long *)&mode) != NO_ERROR) |
| 684 | { |
| 685 | log_error("net", "Setting %s mode for %s socket failed (%s)", socket_str[i], mode_str, net_error_message().c_str()); |
| 686 | } |
| 687 | #else |
| 688 | if(ioctl(sockets[i], FIONBIO, (unsigned long *)&mode) == -1) |
| 689 | { |
| 690 | log_error("net", "Setting %s mode for %s socket failed (%s)", socket_str[i], mode_str, net_error_message().c_str()); |
| 691 | } |
| 692 | #endif |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | int net_set_non_blocking(NETSOCKET sock) |
| 700 | { |
no test coverage detected