Gatica

Gatica

Calling Elixir process from a Port Driver

I’m trying to figure out a way to initiate a call to the Elixir application from a linked port driver. I have a library in C, which functions as a server. It creates a thread when it’s initialised from Elixir, which sevices network requests in C. I can make calls from Elixir down to the driver and send messages to it. However, if the server needs to respond to a request, it cannot make calls back up to Elixir. I thought this would be straightfoward with driver_output() function, but then I don’t have the driver handle and I suppose the message in Elixir would be handled asynchronously too.

Any suggestions as to how this can be done?

Most Liked

garazdawi

garazdawi

Erlang Core Team

You cannot call Erlang/Elixir from a driver or nif.

The thread that does the request could wait on a futex (or similar) after sending a message to the process that needs to run some Erlang/Elixir code. Then when the process is done it can call the driver/nif again and deliver the response and trigger the futex.

It is not easy to do things this way, but it is possible. For instance, I think that the wx application in Erlang handles some of the wx callbacks this way.

evadne

evadne

I have a cracking idea.

• You might be able to cheat by passing a reference to a separately handled UNIX socket.

• Alternatively, make your external thing a C node and integrate Erlang Distribution (i.e. change the design). Still, have your Elixir app spawn & manage it, possibly via saleyn/erlexec or some other libraries that were proven to be robust.

Making the external thing into its own C / Java node, is a viable option, and I have used this approach with great success.

Where Next?

Popular in Questions Top

bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement