libancil had growing pains, starting with incompatibility with -std=c++11

Users then had general failures in libancil_get_fd. It might be worth going back to IPC messages like Broadcast 2000 used.  The file descriptors aren't moving any frame buffers, just commands & responses.  File descriptors might have only gotten used because they were novel.  The problem with IPC messages is deleting them after a crash.  There are also ordinary sockets.


The general design is there's a global FileServer which runs in its own process, with its own memory space.  It takes commands to create & destroy FileForks.  When it creates a FileFork, it has a pointer to it in ForkServer's memory space, with a file descriptor & the pid of the FileFork. 

The next trick is FileServer creates a dummy FileFork object in the mane program's memory space.  The dummy FileFork looks like the real FileFork in the FileServer's memory space.  It takes all the same commands but forwards them over the file descriptor to the real FileFork.

The file_fork in the File object is the dummy FileFork.  A better name might have been a wrapper FileFork.  Commands are sent to the real file fork by writing to the parent_fd in the dummy FileFork.  The command is read from the child_fd in the real FileFork in its own process.  The result is written to the child_fd in the real FileFork & read from the parent_fed in the dummy FileFork.

It would be better to call it a parent FileFork instead of a dummy, to match the naming of the file descriptors.  It would also be clearer to split FileFork/ForkWrapper into parent fork & child fork classes.  It's only used by FileFork & FileServer.  The parent fork would create the child fork class.  The parent fork would have send_command & read_result.  The child fork would have handle_command & send_result.

What needs to happen is replacement of the parent_fd & child_fd with a socket.  libancil might have been built on top of sockets, making the exercise worthless though.

 

There's no need for FileServer to create a parent FileFork, manetain a pointer to it, & return a dummy copy.  It just needs to create a parent FileFork with a socket pair for communicating with the child FileFork & return the parent.  Of course, FileFork needs to be split into a parent & child too.

 

---------------------------------------------------------------------------------------------------------------------

Reviewing the source code more, the FileServer actually needs the pointer to the parent FileFork.  It needs to join with the child fork.

It actually uses a socket pair between the parent & child forks.  The libancil call is only for forwarding the parent socket to the dummy.  It really needs a 2nd socket pair & a relay.

Tunnel all commands through FileServer: 

 

What probably needs to happen is all the communication with all the FileForks getting wrapped in FileServer commands.  The trick is forwarding the responses.  It has to send a 2nd command to read the result. Instead of returning a FileFork dummy, FileServer needs to return a wrapper object which wraps send_command & read_result.

There's a case where a 2nd process gets a send_command between the 1st process's send_command & read_result.  To keep read_results from multiple send_commands from getting interleaved, every file operation now needs to lock the FileServer & the FileServer needs to warn if it isn't locked.  

 

The only other thing that might work is making FileServer read commands from its parent process & responses from all of its child processes, using a select call.  It would buffer up to 1 response from the child processes while handling commands from the mane program.  It would be quite a change to the ForkWrapper which previously just read commands from its parent.  It would be a daisychaining feature in the ForkWrapper.

This too is a complicated mess.  The ForkWrapper thread is normally waiting for the next command.  It only reads responses when the user's handle_command() calls read_result().  It doesn't have a persistent thread always reading responses.

 

1 read_result per send_command:

 

 Another way is to have a forwarded send_command always wait for a response before returning, then buffer the response for the next call to read_result, since the read_result sometimes comes after a while loop repeats.  There would be no way for a 2nd process's result code to get between the 1st command's response.  File & FileServer always call read_result after send_command, except for the DELETE_FILEFORK command.  That could be fixed.

 

Multiple read_result per send_command:

The next problem is after making sure every send_command calls read_result, there's another case of multiple read_results happening after 1 send_command, for updating a progress bar.  This requires sending a dummy command to get the tunnel to read another result code.  In this case, the tunnel is locked by the dummy send_command & it blocks until it receives the next result code.

The FileServer is mighty busy forwarding all the commands for every file, but it works.  The mane performance loss from doing this is only 1 frame may be decoded at a time.  When the timeline is scrolling, video playback now stutters when it draws the timeline picons.  Compositor playback stutters when scrubbing on the viewer window.  The only way around it would be to go back to direct communication between the dummy FileFork & the true FileFork.



---------------------------------------------------------------------------------------------------------------------


Another week ends at 31 miles before the weekend rain.  Much harder to push a 175lb lion than it was to push a 170lb lion.  Not sure where the weight gain came from.  It may be the protein supplements.




Comments

Popular posts from this blog