erlang-ports

Converting Erlang-C port example to Erlang-Golang

两盒软妹~` 提交于 2020-02-01 10:31:29
问题 I'm trying to write a Golang driver for Erlang, accesible via an Erlang port. I've started with the Erlang C port example, which works fine: http://www.erlang.org/doc/tutorial/c_port.html Now I'm trying to port the C code to Golang; just trying to echo a simple 'Hello World\n' message, using '\n' as the delimiter. So my Golang code is as follows: package main import ( "bufio" "fmt" "os" ) func main() { reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text: ") bytes, _ := reader.ReadBytes(

Erlang ports and thread safety

99封情书 提交于 2019-12-12 19:11:18
问题 I'm looking to call a C function from an Erlang process via an Erlang port, as described here: http://www.erlang.org/doc/tutorial/c_port.html In production I will need multiple Erlang processes calling the C function in parallel, each with a different set of arguments. My question is, will this be thread safe at the C function level ? The docs talk about the controlling Erlang process creating a 'connected process', which it sounds as if is responsible for creating an isolated instance of the

Erlang: Interfacing with Xalan: port driver or nif?

左心房为你撑大大i 提交于 2019-12-12 13:53:15
问题 I'd like to get a real XSLT processor working with erlang. Which would be the best interface, nif or port driver? According to the nif documentation, nif calls block the runtime, so they should not take long. Is processing a long xml document too long? Also, I'd like to allow erlang callbacks during the transformation. Does that seem possible? Possible with nif but not port drivers or vice versa? I've never written any C, so I figured this would be good introduction. Xalan is C++. I assume

Open a Python port from Erlang: no reply messages

杀马特。学长 韩版系。学妹 提交于 2019-12-12 05:16:27
问题 Based on Chapter 12 of the OTP in Action book and Cesarini's book I wrote this Erlang code: Erlang: p(Param) -> ?DBG("Starting~n", []), Cmd = "python test.py", Port = open_port({spawn,Cmd}, [stream,{line, 1024}, exit_status]), ?DBG("Opened the port: ~w~n", [Port]), Payload = term_to_binary(list_to_binary(integer_to_list(Param))), erlang:port_command(Port, Payload), ?DBG("Sent command to port: ~w~n", [Payload]), ?DBG("Ready to receive results for command: ~w~n", [Payload]), receive {Port,

C and Erlang: Erlang Port example

久未见 提交于 2019-12-03 06:48:26
Disclaimer: The author of the question has an average knowledge of Erlang and a basic knowledge of C. I am reading the Interoperability Tutorial User Guide now. I have successfully compiled the complex.c example and it works with the Erlang Port without any problems. However, I would like to understand how the actual C code works. I understand it in general: in the example it reads 2 bytes from the standard input and checks the first byte. Depending on the first byte it calls either foo or bar function. This is the limit of my understanding of it right now. So, if we take both erl_comm.c : /*