Skip to content
Merged
Changes from 3 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
9 changes: 8 additions & 1 deletion 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 @@ -21,6 +22,8 @@
ioctl_supported = False
pass

# All ioctls aren't supported on MacOS.
is_macos = platform.system() == "Darwin"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like having two flags ioctl_supported and is_macos for the same purpose. Maybe we could import ioctl on Linux only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Changed the flag to a single is_linux instead of the previous two.


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -275,6 +278,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 +408,7 @@ def recv(
self.max_buffer
)

if ioctl_supported:
if ioctl_supported and not is_macos:
result_buffer = ioctl(
self._socket.fileno(),
SIOCGSTAMP,
Expand Down
Loading