The project has hit a wall when I found that more than one socket needed to be read, because browsers tend to get webpages from multiple connections.
TL;DR : I have re-designed the system around poll() and the timeouts and other peripheral details are now handled in a wrapper function.
The latest archive doesn't contain a working system but the foundations seem to work well. I still need to modify the server but the surrounding code is pretty good now, and the conversion will be easy.
The new code exposes a number of global variables and functions :
- timeout_counter (flag that signals the expiration of a timeslice in polling mode)
- abort_program (flag that is set when the program must quit)
- poll_HTTaP() (the HTTaP code to poll and serves files)
- init_HTTaP() (run before the main loop)
- HTTaP_mode_block() (signals that the host program has finished heavylifting)
- HTTaP_mode_poll() (signals that the host program has work to do and needs the CPU for himself)
Overall it looks like collaborative multitasking, with timeout management sprinkled all over the code.
The constraint is that each slice of work must be reasonably short (100ms ?) to keep the system responsive.
- When all the work is done, call HTTaP_mode_block() to go into blocking mode and save/yield CPU while waiting for the next command.
- When a new command is received that requests more work, call HTTaP_mode_poll()
Behind the scene, it's not trivial but it seems to work well. The functions are rather well layered and the timeouts seem to do their work.
I have so far provided a "dumb" application that reads orders from the command line and wastes time writing to the screen, it will soon include the real socket server instead.
The cool part is that the host program has very few constraints and it should work nicely with GHDL !
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.