Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPC via abstract unix domain sockets #4

Merged
merged 34 commits into from
Dec 27, 2024
Merged

Conversation

serges147
Copy link
Collaborator

@serges147 serges147 commented Dec 23, 2024

  • Added new "SDK" library target; added ocvsmd-cli executable target to consume the SDK.
  • Posix calls now are wrapped with platform::posixSyscallError (which does retries on EINTR). For now only IPC stuff correctly wrapped; the same for other places (like executors, udp sockets, etc.) to be continued...

Also:

  • Now compiles on macOS by adding kqueue-based implementation of executor for Darwin. Thank you @thirtytwobits for sharing your original implementation (I did some fixes related to kevent timeout calculations - now it's nanoseconds based instead of seconds).

@serges147 serges147 marked this pull request as ready for review December 23, 2024 12:58
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay)
std::memcpy(addr.sun_path,
abstract_socket_path.c_str(),
std::min(sizeof(addr.sun_path), abstract_socket_path.size()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On BSD I'm gonna return back to usual Unix domain sockets - BSD doesn't support abstract ones.

Copy link
Collaborator Author

@serges147 serges147 Dec 23, 2024

Choose a reason for hiding this comment

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

BTW, @thirtytwobits let me know please, do you seek that our ocvsmd could run on macOS?
For now it is not a problem (besides the above comment about abstract unix domain sockets), but I would like to know whether it worth to spend a bit extra efforts on this or not. Thnx

Choose a reason for hiding this comment

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

It's not required for the contract work, no. It's always helpful to have for debugging.

Copy link

@thirtytwobits thirtytwobits left a comment

Choose a reason for hiding this comment

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

So far so good but how does the client get server notifications? For example, what's the flow here if the client starts a firmware update and the server is monitoring it? How does the client get the firmware update progress from the server?

~UnixSocketClient();

bool connect_to_server();
void send_message(const std::string& message) const;

Choose a reason for hiding this comment

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

can we also support string_view?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this send_message was just to prove send and receive. real communication api of course will be different. probably passing back and forth some serialized structures.

CETL_NODISCARD libcyphal::IExecutor::Callback::Any registerListenCallback(
libcyphal::IExecutor::Callback::Function&& function) const;

void accept();

Choose a reason for hiding this comment

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

Shouldn't this return an error?

Copy link
Collaborator Author

@serges147 serges147 Dec 23, 2024

Choose a reason for hiding this comment

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

Normally it should but in my case there is nowhere to return it actually. See call site:

    ipc_server_callback_ = ipc_server_.registerListenCallback([this](const auto&) {
        //
        ipc_server_.accept();
    });

// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay,hicpp-no-array-decay)
std::memcpy(addr.sun_path,
abstract_socket_path.c_str(),
std::min(sizeof(addr.sun_path), abstract_socket_path.size()));

Choose a reason for hiding this comment

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

It's not required for the contract work, no. It's always helpful to have for debugging.

const std::string socket_path_;
int server_fd_;
platform::IPosixExecutorExtension* const posix_executor_ext_;
std::unordered_map<int, std::unique_ptr<detail::ClientContext>> client_contexts_;

Choose a reason for hiding this comment

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

nit: might be more elegant to use a std::set<std::unique_ptr<detail::ClientContext>> where detail::ClientContext had a int GetHandle() const method and you provided a custom comparitor that used that.

@@ -67,6 +67,13 @@ add_definitions(
-DVCS_REVISION_ID=0x${vcs_revision_id}ULL
-DNODE_NAME="org.opencyphal.ocvsmd"
)
if (DEFINED PLATFORM_LINUX_TYPE)
if(${PLATFORM_LINUX_TYPE} STREQUAL "bsd")
add_definitions(-DPLATFORM_LINUX_TYPE_BSD)
Copy link
Member

Choose a reason for hiding this comment

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

BSD is not Linux, it's a different kernel family, so PLATFORM_LINUX_TYPE may need renaming.

if(${PLATFORM_LINUX_TYPE} STREQUAL "bsd")
add_definitions(-DPLATFORM_LINUX_TYPE_BSD)
elseif(${PLATFORM_LINUX_TYPE} STREQUAL "debian")
add_definitions(-DPLATFORM_LINUX_TYPE_DEBIAN)
Copy link
Member

Choose a reason for hiding this comment

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

Debian comes with BSD kernels as well, not just Linux. While we are at it, Linux is a kernel, not an OS, that would be GNU/Linux. Should we not simply go like PLATFORM_DEBIAN, PLATFORM_BSD? Although then it seems odd that one of them is an OS while the other is a kernel.

@serges147 serges147 merged commit 94fb76d into main Dec 27, 2024
14 checks passed
@serges147 serges147 deleted the sshirokov/ipc_unix_sock branch December 27, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants