Skip to content

Commit f0b330d

Browse files
Added macos support (#15)
- CAN transport now under Linux only. - Merged `kqueue` fixes (from the `demos` repo). - Fixed warning in logs (due to expected `EINTR` "error" from `::kevent` & `epoll_wait`). --------- Co-authored-by: Sergei Shirokov <sshirokov@malwarebytes.com>
1 parent 9a086e9 commit f0b330d

File tree

7 files changed

+37
-20
lines changed

7 files changed

+37
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ set(test_dir "${CMAKE_SOURCE_DIR}/test")
2626
set(include_dir "${CMAKE_SOURCE_DIR}/include")
2727
set(submodules_dir "${CMAKE_SOURCE_DIR}/submodules")
2828

29+
set(CXX_FLAG_SET "")
2930
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3031
# Disable PSABI warnings in GCC (on RPi).
3132
list(APPEND CXX_FLAG_SET "-Wno-psabi")
3233
endif()
33-
3434
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:${CXX_FLAG_SET}>")
3535

3636
# clang-format

CMakePresets.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@
7575
"cacheVariables": {
7676
"CMAKE_C_COMPILER": "clang",
7777
"CMAKE_CXX_COMPILER": "clang++"
78-
},
79-
"vendor": {
80-
"jetbrains.com/clion": {
81-
"toolchain": "Clang19"
82-
}
8378
}
8479
}
8580
],

include/ocvsmd/platform/bsd/kqueue_single_threaded_executor.hpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ class KqueueSingleThreadedExecutor final : public libcyphal::platform::SingleThr
108108
if (kqueue_result < 0)
109109
{
110110
const auto err = errno;
111+
if (err == EINTR)
112+
{
113+
// Normally, we would just retry a system call (`::kevent`),
114+
// but we need updated timeout (from the main loop).
115+
return cetl::nullopt;
116+
}
111117
return libcyphal::transport::PlatformError{PosixPlatformError{err}};
112118
}
113119
if (kqueue_result == 0)
@@ -185,7 +191,7 @@ class KqueueSingleThreadedExecutor final : public libcyphal::platform::SingleThr
185191
AwaitableNode(Self& executor, Callback::Function&& function)
186192
: CallbackNode{executor, std::move(function)}
187193
, fd_{-1}
188-
, events_{0}
194+
, filter_{0}
189195
{
190196
}
191197

@@ -194,7 +200,7 @@ class KqueueSingleThreadedExecutor final : public libcyphal::platform::SingleThr
194200
if (fd_ >= 0)
195201
{
196202
KEvent ev{};
197-
EV_SET(&ev, fd_, events_, EV_DELETE, NOTE_DELETE, 0, 0);
203+
EV_SET(&ev, fd_, filter_, EV_DELETE, 0, 0, 0);
198204
::kevent(getExecutor().kqueuefd_, &ev, 1, nullptr, 0, nullptr);
199205
getExecutor().total_awaitables_--;
200206
}
@@ -203,14 +209,14 @@ class KqueueSingleThreadedExecutor final : public libcyphal::platform::SingleThr
203209
AwaitableNode(AwaitableNode&& other) noexcept
204210
: CallbackNode(std::move(static_cast<CallbackNode&&>(other)))
205211
, fd_{std::exchange(other.fd_, -1)}
206-
, events_{std::exchange(other.events_, 0)}
212+
, filter_{std::exchange(other.filter_, 0)}
207213
{
208214
if (fd_ >= 0)
209215
{
210216
KEvent ev{};
211-
EV_SET(&ev, fd_, events_, EV_DELETE, NOTE_DELETE, 0, 0);
217+
EV_SET(&ev, fd_, filter_, EV_DELETE, 0, 0, 0);
212218
::kevent(getExecutor().kqueuefd_, &ev, 1, nullptr, 0, nullptr);
213-
EV_SET(&ev, fd_, events_, EV_ADD | EV_CLEAR, NOTE_WRITE, 0, this);
219+
EV_SET(&ev, fd_, filter_, EV_ADD, 0, 0, this);
214220
::kevent(getExecutor().kqueuefd_, &ev, 1, nullptr, 0, nullptr);
215221
}
216222
}
@@ -224,22 +230,22 @@ class KqueueSingleThreadedExecutor final : public libcyphal::platform::SingleThr
224230
return fd_;
225231
}
226232

227-
std::uint32_t events() const noexcept
233+
std::int16_t filter() const noexcept
228234
{
229-
return events_;
235+
return filter_;
230236
}
231237

232-
void setup(const int fd, const std::uint32_t events) noexcept
238+
void setup(const int fd, const std::int16_t filter) noexcept
233239
{
234240
CETL_DEBUG_ASSERT(fd >= 0, "");
235-
CETL_DEBUG_ASSERT(events != 0, "");
241+
CETL_DEBUG_ASSERT(filter != 0, "");
236242

237243
fd_ = fd;
238-
events_ = events | EVFILT_VNODE;
244+
filter_ = filter;
239245

240246
getExecutor().total_awaitables_++;
241247
KEvent ev{};
242-
EV_SET(&ev, fd, events_, EV_ADD | EV_CLEAR, NOTE_WRITE, 0, this);
248+
EV_SET(&ev, fd, filter_, EV_ADD, 0, 0, this);
243249
::kevent(getExecutor().kqueuefd_, &ev, 1, nullptr, 0, nullptr);
244250
}
245251

@@ -253,8 +259,8 @@ class KqueueSingleThreadedExecutor final : public libcyphal::platform::SingleThr
253259

254260
// MARK: Data members:
255261

256-
int fd_;
257-
std::uint32_t events_;
262+
int fd_;
263+
std::int16_t filter_;
258264

259265
}; // AwaitableNode
260266

include/ocvsmd/platform/linux/epoll_single_threaded_executor.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ class EpollSingleThreadedExecutor final : public libcyphal::platform::SingleThre
9999
if (epoll_result < 0)
100100
{
101101
const auto err = errno;
102+
if (err == EINTR)
103+
{
104+
// Normally, we would just retry a system call (`::epoll_wait`),
105+
// but we need updated timeout (from the main loop).
106+
return cetl::nullopt;
107+
}
102108
return libcyphal::transport::PlatformError{PosixPlatformError{err}};
103109
}
104110
if (epoll_result == 0)

src/daemon/engine/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ add_library(ocvsmd_engine
4747
config.cpp
4848
cyphal/file_provider.cpp
4949
engine.cpp
50-
platform/can/socketcan.c
5150
platform/udp/udp.c
5251
svc/file_server/list_roots_service.cpp
5352
svc/file_server/pop_root_service.cpp
@@ -62,6 +61,11 @@ target_link_libraries(ocvsmd_engine
6261
PUBLIC ${engine_transpiled}
6362
PUBLIC ocvsmd_common
6463
)
64+
if (${PLATFORM_OS_TYPE} STREQUAL "linux")
65+
target_sources(ocvsmd_engine
66+
PRIVATE platform/can/socketcan.c
67+
)
68+
endif ()
6569
target_include_directories(ocvsmd_engine
6670
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
6771
)

src/daemon/engine/cyphal/transport_helpers.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ struct TransportHelpers
6161

6262
}; // Printers
6363

64+
#ifdef __linux__
65+
6466
struct CanTransientErrorReporter
6567
{
6668
using Report = libcyphal::transport::can::ICanTransport::TransientErrorReport;
@@ -111,6 +113,8 @@ struct TransportHelpers
111113

112114
}; // CanTransientErrorReporter
113115

116+
#endif // __linux__
117+
114118
struct UdpTransientErrorReporter
115119
{
116120
using Report = libcyphal::transport::udp::IUdpTransport::TransientErrorReport;

src/daemon/engine/engine.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ cetl::optional<std::string> Engine::init()
5959
}
6060
else
6161
{
62+
#ifdef __linux__
6263
if (auto maybe_can_transport_bag = cyphal::CanTransportBag::make(memory_, executor_, config_))
6364
{
6465
any_transport_bag_ = std::move(maybe_can_transport_bag);
6566
}
6667
else
68+
#endif // __linux__
6769
{
6870
std::string msg = "Failed to create Cyphal transport.";
6971
logger_->error(msg);

0 commit comments

Comments
 (0)