Can gen_tcp/inets store connection-specific user state?
Tony Arcieri
tony.arcieri@REDACTED
Fri Jul 16 04:15:30 CEST 2010
Many operating systems provide high-performance stateful I/O multiplexing
APIs. Some examples of these APIs include Linux's epoll, *BSD's kqueue,
Solaris's event completion ports, and Windows I/O completion ports.
A common characteristic of these APIs is the ability to include a pointer to
a piece of user state. This provides a simple way to look up the state
necessary to dispatch an event. A skillful user of these APIs will bundle
all the state necessary to dispatch a request into a single pointer, and
these APIs will keep track of that pointer, all the way down to the kernel
level.
As far as I can tell, gen_tcp/inets do not do this. I am not seeing any
APIs that will allow me to provide an Erlang term when I flip on active mode
on a particular socket which will be delivered in the messages I receive
from inets.
Am I missing something? Is there a way to do this? If not, the recourses I
have seem particularly disadvantageous compared to the underlying API
carrying a single piece of state for me from end-to-end. Either I can use a
proxy process per connection, involving all the complexity of managing an
external process in the API I expose to an end user, and requiring a process
per connection where if gen_tcp/inets held onto the state for me I'd only
require one, or having a single process which used a mapping data structure
to go between the port the message originated from and the piece of user
state I actually care about. I find both of these solutions particularly
suboptimal, especially considering that the kernel-level APIs are designed
to round trip a particular piece of user state you care about end-to-end.
The underlying functionality is there at the kernel level, but as far as I
can tell Erlang does not expose it as a language. Is there something I'm
missing?
--
Tony Arcieri
Medioh! A Kudelski Brand
More information about the erlang-questions
mailing list