Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions can/interfaces/udp_multicast/bus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import errno
import logging
import platform
import select
import socket
import struct
Expand All @@ -13,14 +14,9 @@

from .utils import check_msgpack_installed, pack_message, unpack_message

ioctl_supported = True

try:
is_linux = platform.system() == "Linux"
if is_linux:
from fcntl import ioctl
except ModuleNotFoundError: # Missing on Windows
ioctl_supported = False
pass


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -275,6 +271,10 @@ def _create_socket(self, address_family: socket.AddressFamily) -> socket.socket:
# Allow multiple programs to access that address + port
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

# Option not supported on Windows.
if hasattr(socket, "SO_REUSEPORT"):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)

# set how to receive timestamps
try:
sock.setsockopt(socket.SOL_SOCKET, SO_TIMESTAMPNS, 1)
Expand Down Expand Up @@ -401,7 +401,8 @@ def recv(
self.max_buffer
)

if ioctl_supported:
if is_linux:
# This ioctl isn't supported on Darwin & Windows.
result_buffer = ioctl(
self._socket.fileno(),
SIOCGSTAMP,
Expand Down