2 ms·
Read the source to Putty sometime. The main program is one big, big function with a big, big loop and switch in it. Each place where it does something that wou
by ncmncm 6y ago
Read the source to Putty sometime.
The main program is one big, big function with a big, big loop and switch in it. Each place where it does something that would (otherwise) block, it sets a state variable to match a case label right after, does a non-blocking version, and breaks. (This is done with a macro.)
After the break, it stashes the state, and if anything is ready, switches to that state and re-enters the switch. Otherwise, it sleeps waiting for work that can proceed.
As a colleague remarked, "I love it, and hate myself for loving it."