I have a macOS app which acquires data directly from a piece of hardware. The app can generate a transfer file to enable other instances to run in remote mode. This is updated once every 10 seconds.
There is a Windows version of the software too, developed by the manufacturer of the hardware, and this too can operate in master/remote mode.
Some users have mixed Windows/Mac systems and want to use this master/remote mode cross-platform. It does work, except for one peculiarity: in my development environment I’m storing the transfer file on a Synology NAS drive, which works fine for the macOS app.
But the Windows machine caches the file, so after the first read it just gets the same file content time after time.
Apparently this read-cacheing can be prevented on Windows by using the flag FILE_FLAG_NO_BUFFERING when creating the file. But how can I do this on a Mac?
So… a few notions. The Mac app repeatedly writes data to a file on a shared driver. A Windows app periodically reads this file, but the read data never changes after the first read.
First, are you closing and re-opening the file, or just keeping the file open and reusing the stream? I’d suggest closing it after each read and reopening it as needed.
If that doesn’t help, I suggest additionally try recreating the Folderitem that points to the data file. This may be enough to disrupt any caching scheme.
Thirdly, make sure the Mac app is deleting the existing file instead of writing over it.
Fourthly - and a little more desperately - have the Mac app delete the existing file and write a new one with a different name, like “data-2458986412579” (use a UUID here) and the Windows app opens the first file in the folder that matches the filename pattern.
You might also consider what protocol your Windows machine is using to connect to the shared folder. If you’re using an older version of anything, try a newer version.
OK, on the Mac side I’m only writing. The Windows app which does the reading is written by somebody else (the hardware developer) and I don’t know what they do. [Though my Mac app also reads it, if it’s in that mode, and has no problems.]
But to answer the point – yes, I am closing after each write. I check if it exists and, if not, create it. Otherwise I just open it. In both cases I then write to it and close it.
I will try the combination of these two: delete the file before writing, then recreate it.
Oh, I see. I didn’t realize that the Windows software is set in stone. Most of my suggestions were for the Windows code - I thought you were developing it as well.
In that case, you’re probably stuck making policy changes on either the Windows client OS or whatever OS the server is running.
Although I just had a thought - I wonder if you could write a little utility that runs on the Windows client OS frequently “touches” the data file, making it appear to have changed (see the Unix utility ‘touch’ if you’re not familiar). That might cause the local OS to flush the cache. It would have to run pretty frequently.
Or perhaps write a utility to run on the Windows client to copy the data file from the server - possibly using the rotating filename - and place it into a local folder for the Windows software to read.