I am trying to find way to create a semaphore like functionality between a JS script run on a browser and a C++ program. My application is a real-time log file viewer. I have an application that logs periodically to a file. I am going to extract some information from that file and display on a browser using JS. But the problem is this file can get pretty big and having to go through the entire file periodically in JS is very slow and ineffective.
So I my thinking was to have a separate application read the file periodically and write to another file 'only' the new content. Then the JS can go through that smaller file and update its values. This can be done effectively with seek
and tellg
functions in C++.
But I can't have the JS and the C++ program running asynchronously. I need some way for the JS and the C++ program to sync with some kind of locking mechanism. For example C++ will take the lock and then read the log file and update the new contents. Then when the lock is available JS will lock it and display the contents and so on. Of course I need some kind of counter to make sure the C++ program will not overwrite before the JS reads the data.
Anyway you get the idea what I want to achieve. I came across 'Native Client' by Google. This was perfect as I can easily exchange messages back and forth between the JS and the C++ program. But unfortunately when I use Native Client it doesnt allow me to read/write to local files. So my C++ program has no access to read the log file.
Other way was to use Web Storage, but there is no consistent way for the C++ program to read the data written by the Web storage. So that doesn't work either.
If you have any idea please do share. Thanks.