Unsatisfied with my current approach I'm just trying to redesign the way I build protocol stacks in Erlang. The feature ordered by importance:
Performance
Flexibility and implementation speed adding new protocol variants
It would help development to explore the protocol variants from the shell
My current model (alreday described in this question) is getting at its limits besides the ugly asymmetry of send() by function call and receive by message.
The overall picture of the whole protocol engine looks like this:
Bottom part:
There a several ports or maybe also sometimes a gen_tcp at the bottom of each stack (there are multiple identical stacks for independent channels so we can't be too static here just registering processes, have to pass Pids everywhere.
On top of the ports are a few modules that are managed by supervisor (started with the system and in the absence of errors staying the whole lifetime).
Top part:
Triggered by event occurrence (in the general sense not in the event_handler sense) are connection oriented protocol ends (e.g. with
connect()
andclose()
semantics.The top end of the protocol stack can probably only be started dynamically because the modules stacked on top of each other to form the stack are dynamically configurable and might change from connection to connection.
Currently planned would be passing a List of module names + optional params from the toplevel that get consumed while
connect()
is called down the stack.Toplevel processes will be linked so when anything goes wrong here the whole connection fails.
Types of modules and types of communication between them
There are several kinds of modules found so far:
Stateless filter modules
Modules with state, some fit gen_server, some gen_fsm but most will probably be simple server loops since selective receive will be useful and simplify code quite often.
Types of communication between layers:
Independent sending and receiving of packets (independent as seen from the outside)
Synchronous calls that send something, block until there is a answer and then return the result as return value.
Multiplexers that talk down to multiple modules (thats my definition here to ease discussion)
Demultiplexers that have different attachment points (named by atoms currently) to talk with upward facing modules.
Currently my only demultiplexers are in the statical bottom part of the stack and not in the dynamically created top part. Multiplexers are only in the top part currently.
In the answers and comments of my linked previous question handling I heard that generally the API should only consist of functions and not messages and I concur with this unless convinced otherwise.
Please excuse the lengthy explanation of the problem but I think it is still of general use for all kinds of protocol implementation.
I will write what I have planned so far in the answers and also will also explain the resulting implementation and my experience with it later in order to achieve something generally useful here.