Files
alcove/examples
Michael Santos 71117bcefd Multiplex erlang process access to the port
Allow any erlang processes to send messages into the port, similar
to the way port drivers can respond directly to a process. The Unix PID
fork path is used as the key to map the port response to the Erlang PID
by the gen_server.

The current implementation is an experiment only and has a race
condition. Process A calls into the gen_server and blocks. Process B calls
into the port for the same Unix fork path and blocks. The response for
both requests will be sent to process B and process A will block forever.

In other words, the last erlang process to make a request to the fork
path becomes the controlling process. If the erlang process dies, any
data generated by the Unix process is sent to the process that started
the gen_server.

What the behaviour should be needs to be defined. For example, using the
gen_tcp behaviour of controlling_process would be problematic: since the
response always goes to the controlling process, a call from another
erlang process would hang. After the Unix process has called exec(),
allowing multiple processes to send in data may make sense.

Making the controlling process the only process privileged to talk to
the fork path would have some weird side effects:

* data for the fork path would have to be serialized through the
  controlling process

* if a non-owning process sends a message to the fork path, either we
  have to extend the type spec for each call to include
  {error,not_owner} or we send a badsig exception and the client is
  forced to wrap each call in a try/catch

There should also be a concept of linking between unix and erlang
processes:

* processes are unlinked

    * erlang process dies: stdout/stderr from the unix process should
      be dropped

    * unix process dies: controlling process gets the normal exit
      messages (exit_status, termsig)

* processes are linked

    * erlang process dies: unix process gets a SIGKILL

    * unix process dies: erlang process gets an exit(kill)

* erlang process monitors unix process (?)

    * unix process dies: erlang process gets a 'DOWN' message

To test the concept works, modify the tcplxc example to talk directly to
the port from each erlang container process (the example needs much more
cleanup and should be converted to an OTP process).
2014-12-08 11:56:45 -05:00
..
2014-10-26 10:42:54 -04:00