Skip to content

fruitsamples/FileNotification

Repository files navigation

{\rtf1\mac\ansicpg10000\cocoartf102
{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;\f2\fnil\fcharset77 LucidaGrande;
}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww13940\viewh14680\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural

\f0\b\fs36 \cf0 FileNotification Read Me
\f1\b0\fs26 \
\
Kqueue notifications were introduced in Mac OS X 10.3 to provide a file notification API.  The general recommended usage is to create a separate thread, open a file descriptor to the file system object, and then block on the call to kevent.\
\
Looking at the sample source code:\
Within DisplaySimpleWindow() we first initialize our MyMPTaskInfo structure used to pass information into our MP thread, which may not be accessible or safe to initialize from our thread.  We then create the MP thread passing in the initialized MyMPTaskInfo structure.\
\
Most of the interesting work is done in the small MyMPTask() routine on an MP thread.  Here we define the events we are interested in watching, open file descriptors to the directories we are watching , and block on the call to kevent().  If any of the defined events occurs to one of the file descripters we have opened, the call to kevent() unblocks, and we post the information back to the main event queue for display.  The routine PostKQueueEvent() is responsible for setting up out custom CarbonEvent and posting it to the main event queue.  After the event is posted we block on our call to kevent() again until another event is received.\
\

\f0\b When should the kqueue mechanism be used?
\f1\b0 \
\
This solution is ideal for watching drop boxes, or maintaining up-to-date status of a number of directories.  For instance if you application presents views similar to the Finder views, rather than polling for changes to each viewed directory, you should consider a kqueue notification mechanism instead.\
\

\f0\b There are limitations to be aware of:
\f1\b0 \
\
Because a file descriptor must be opened  for each file and folder that is being watched it is not efficient or possible to use this mechanism to watch all changes occurring to an entire disk.\
\
If the folder you're watching is on an NFS server, you won't be notified of changes by other network users.  However SMB and AFP do support a "push" model of notifications.\
\
kqueues may not be supported by all file systems.\
\

\f0\b More kqueue information:\

\f1\b0 \

\f2 Typing "man 2 kqueue" in the Terminal will display the kqueue man page.\
\
Either click the "?" from the FileNotification sample application, or read the enclosed "kqueue.pdf" file for more in-depth information on kqueues.}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published