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

Result of calls to enif_send #293

Closed
evnu opened this issue Dec 12, 2019 · 2 comments
Closed

Result of calls to enif_send #293

evnu opened this issue Dec 12, 2019 · 2 comments

Comments

@evnu
Copy link
Member

evnu commented Dec 12, 2019

enif_send returns a flag, indicating if the send succeeded or not. From the documentation:

Returns true if the message is successfully sent. Returns false if the send operation fails, that is:

  • *to_pid does not refer to an alive local process.
  • The currently executing process (that is, the sender) is not alive.

Functions such as Env::send() or OwnedEnv::send_and_clear() could indicate the success with Result.

@evnu
Copy link
Member Author

evnu commented Dec 12, 2019

Currently, enif_send is only used in Env::send() and OwnedEnv::send_and_clear(). For OwnedEnv, we know that a failure indicates that to_pid is dead, as we do not send from a process here. For Env::send(), both the sending process or the receiver could be dead, but we cannot reliably know which of them is gone. We could therefore distinguish two error cases:

pub enum SendError {
  ReceiverDead,
  SenderOrReceiverDead
}

Then, the signature for OwnedEnv::send_and_clear() would become:

pub fn send_and_clear<F>(&mut self, recipient: &Pid, closure: F) -> Result<(), SendError>
where
   F: for<'a> FnOnce(Env<'a>) -> Term<'a>,

And for Env::send():

pub fn send(self, pid: &Pid, message: Term<'a>) -> Result<(), SendError>

@evnu
Copy link
Member Author

evnu commented Sep 18, 2023

See also this PR: #563

@filmor filmor closed this as completed Jan 5, 2024
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

No branches or pull requests

2 participants