3 ms·
I was thinking about this problem while writing a SMTP server in C this weekend and came to pretty much the same conclusion. Protocols are implemented by FSMs t
by written 9y ago
I was thinking about this problem while writing a SMTP server in C this weekend and came to pretty much the same conclusion. Protocols are implemented by FSMs that can be initialized and composed in various ways, but none of the protocols owns the socket. Socket is owned by the application, and it is the application that polls it and passes the events to the protocol FSMs. This way it's easy to switch to TLS on STARTTLS without any hacks, because application can decide to reconfigure the protocols stack at any time. Managing lifetime for the socket is also simpler, because app does it, and ownership is not passed to the protocol implementation.
It's work in progress, but should be easy to reason about and work with even without using coroutines.