[Mono-list] Fwd: [Mono-osx] FileSystemWatcher

Andreas Färber andreas.faerber at web.de
Fri Jan 19 06:02:12 EST 2007

Hello Miguel,

>> Earlier I was told not to monitor an SMB share because it were
>> implemented using a polling approach for remote shares so instead I
>> connected a Windows drive to an OS X SMB share, monitoring the local
>> changes there. However the same results occurred last time I checked
>> running the DOS app locally on OS X, so without any SMB in  
>> between, so
>> that the latter probably isn't the source of the problem... Also, the
>> same issue occurs when my Mono application performs the changes
>> itself, so I doubt it's an issue with the DOS application performing
>> the changes.
> Mono has a special driver for OSX to handle this (it uses kqueue).
> The source code is in mono/mono/metadata/filewatcher.c

Unfortunately there was no code such as #ifdef MACOSX in there ;-) so  
thanks for this hint.

FileSystemWatcher.cs gives me no hint on why get_MangledFilter might  
have crashed (it's all managed code) but then again I haven't seen  
this crash for a while now.

I don't know kqueue so ... KeventWatcher.cs is not fundamentally  
wrong and there appears to be no way of enabling debug output. There  
are however a number of undocumented magic numbers specified as flags  
in StartMonitoringDirectory:

ev.filter = -4 sets the filter to EVFILT_VNODE.

Then, ev.flags and ev.fflags appear to use decimal flags while in my  
header files they are declared as hexadecimals! Especially 20 as  
opposed to 0x20 (EV_CLEAR and NOTE_RENAME). Might the incorrect clear  
flag ("clear event state after reporting") explain why sometimes  
after some seconds delay I got a notification and afterwards none?

The polling thread (Monitor) sleeps for 500 ms so still wouldn't  
explain the long initial delay of >5 s unless kqueue were so slow...

Also, error handling is missing in some places... For example, if no  
file descriptor can be obtained it is silently ignored just as for  
exceptions in foreach.
More severely, kevent() returns as errors EV_EOF=0x8000 and  
EV_ERROR=0x4000 yet the code only checks if kevent() > 0 but in that  
case always stops monitoring (closing the file), restarts it (opening  
a new file descriptor) and processes the event - reads like a dirty  
hack... but then again I have no experience with kqueue so I can't  
tell. Geoff, is this a workaround that would be obsoleted by changing  
the flags?

And finally: Is it possible to compile only System.dll from SVN and  
copy it into an existing Mono.framework 1.2 instead of compiling a  
separate runtime?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070119/b5754fc7/attachment.html 

More information about the Mono-list mailing list