tags:

views:

166

answers:

6

In bare outlines, I've got an application which looks through the directories at startup and creates special files' index - after that it works like daemon. The other application creates such 'special' files and places them in some directory. What way of informing the first application about a new file (to index it) is the most common, simple (the first one is run-time, so it shouldn't slow it too much), and cross-platform if it is possible?

I've looked through RPC and IPC but they are too heavy (also non-cross-platform and slow (need a lot of features to work - I need a simple light well-working way), probably).

+1  A: 

For windows (NTFS) you can get notification from OS that directory was changed. But it is not crosspl. and not about two apps.

"IPC but them are too heavy" - no no, they are not heavy at all. You should look at named pipes - this IPC is fastest and it is in both Win/Unix-like with slight differences. Or sockets!

Andrey
+7  A: 

Pipes would be one option: see Network Programming with Pipes and Remote Procedure Calls (Windows) or Creating Pipes in C (Unix).

I haven't done this in a while but from my experience with RPC, DCOM, COM, .NET Remoting, and socket programming, I think pipes is the most straightforward and efficient option.

Alek Davis
A: 

Local TCP sockets are guarenteed to work - as already mentioned by Andrey

Shared memory would be another option, take a look at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2044.html

eisbaw
A: 

As Andrey noted, if you agree on the full path ahead of time, you can just have the OS tell you when it's added. All major platforms actually support this in some form. You can use a cross-platform library for this, such as QFileSystemWatcher.

EDIT: I don't think QFileSystemWatcher will cause too much of a performance hit. It definitely relies on the underlying OS for notifications on Linux, FreeBSD, and Mac OS (and I think Windows). See http://qtnode.net/wiki/QFileSystemWatcher

Matthew Flaschen
@Matthew Flaschen, or Boost.Filesystem. But I expect it would devour too much resources. Or wouldn't. Finlay, I need to reindex directory only in case of some special changes.
MInner
+1  A: 

eisbaw suggested TCP. I'd say, to make it even more simple, use UDP. Create a listening thread that will receive packets, and handle it from there - on all applications.

Since it is on the same PC you'll never lose any packet, something that UDP could mistakenly do when on network.

Each application instance will need a special port but this is easy to configure with configuration files that you (I assume) already have.

Keep it simple (:

Poni
A: 

memory mapped files, socket, and named pipes are all highly efficient, cross platform, ipc mechanisms. Well, the apis to access named pipes and memory mapped files differ between POSIX and Win32, but the basic mechanisims are similar enough that its easy to make a cross platform wrapper. Sockets and named pipes tend to be fast because, in inter-process situations, the OS developers (of most common OSs) have built in shortcuts that essentially makes the socket / named pipe write a rather simple wrap of a memory section.

Chris Becke