Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
dc978815
Commit
dc978815
authored
Aug 26, 2010
by
mattijs
Browse files
BUG: have large buffer space
parent
dac1c335
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/OSspecific/POSIX/fileMonitor.C
View file @
dc978815
...
...
@@ -38,6 +38,10 @@ Class
#else
# include <sys/inotify.h>
# include <sys/ioctl.h>
# define EVENT_SIZE ( sizeof (struct inotify_event) )
# define EVENT_LEN (EVENT_SIZE + 16)
# define EVENT_BUF_LEN ( 1024 * EVENT_LEN )
#endif
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
...
...
@@ -132,30 +136,11 @@ namespace Foam
//- File descriptor for the inotify instance
int
fd
;
//- Pre-allocated structure containing file descriptors
fd_set
fdSet
;
//- initialize inotify
inline
fileMonitorWatcher
(
const
label
dummy
=
0
)
:
fd
(
inotify_init
())
{
// Add notify descriptor to select fd_set
FD_ZERO
(
&
fdSet
);
FD_SET
(
fd
,
&
fdSet
);
}
//- test if file descriptor is set
inline
bool
isSet
()
const
{
return
FD_ISSET
(
fd
,
&
fdSet
);
}
//- reset file descriptor
inline
void
reset
()
{
FD_SET
(
fd
,
&
fdSet
);
}
{}
inline
label
addWatch
(
const
fileName
&
fName
)
{
...
...
@@ -164,7 +149,7 @@ namespace Foam
fd
,
fName
.
c_str
(),
// IN_ALL_EVENTS
IN_CLOSE_WRITE
|
IN_DELETE_SELF
|
IN_MODIFY
IN_CLOSE_WRITE
|
IN_DELETE_SELF
//
| IN_MODIFY
);
}
...
...
@@ -214,17 +199,26 @@ void Foam::fileMonitor::checkFiles() const
}
}
#else
// Large buffer for lots of events
char
buffer
[
EVENT_BUF_LEN
];
while
(
true
)
{
struct
timeval
zeroTimeout
=
{
0
,
0
};
//- Pre-allocated structure containing file descriptors
fd_set
fdSet
;
// Add notify descriptor to select fd_set
FD_ZERO
(
&
fdSet
);
FD_SET
(
watcher_
->
fd
,
&
fdSet
);
int
ready
=
select
(
watcher_
->
fd
+
1
,
// num filedescriptors in fdSet
&
(
watcher_
->
fdSet
),
// fdSet with only inotifyFd
NULL
,
// No writefds
NULL
,
// No errorfds
&
zeroTimeout
// eNo timeout
watcher_
->
fd
+
1
,
// num filedescriptors in fdSet
&
fdSet
,
// fdSet with only inotifyFd
NULL
,
// No writefds
NULL
,
// No errorfds
&
zeroTimeout
// eNo timeout
);
if
(
ready
<
0
)
...
...
@@ -233,51 +227,55 @@ void Foam::fileMonitor::checkFiles() const
<<
"Problem in issuing select."
<<
abort
(
FatalError
);
}
else
if
(
watcher_
->
is
Set
(
))
else
if
(
FD_ISSET
(
watcher_
->
fd
,
&
fd
Set
))
{
struct
inotify_event
inotifyEvent
;
// Read first event
ssize_t
nBytes
=
read
(
watcher_
->
fd
,
&
inotifyEvent
,
sizeof
(
inotifyEvent
)
);
// Read events
ssize_t
nBytes
=
read
(
watcher_
->
fd
,
buffer
,
EVENT_BUF_LEN
);
if
(
nBytes
!=
sizeof
(
inotifyEvent
)
)
if
(
nBytes
<
0
)
{
FatalErrorIn
(
"fileMonitor::updateStates(const fileName&)"
)
<<
"
R
ead "
<<
label
(
nBytes
)
<<
" ; expected "
<<
label
(
sizeof
(
inotifyEvent
)
)
<<
"
r
ead
of
"
<<
watcher_
->
fd
<<
" failed with "
<<
label
(
nBytes
)
<<
abort
(
FatalError
);
}
// Pout<< "mask:" << inotifyEvent.mask << nl
// << "watchFd:" << inotifyEvent.wd << nl
// << "watchName:" << watchFile_[inotifyEvent.wd] << endl;
if
(
inotifyEvent
.
mask
%
IN_DELETE_SELF
)
// Go through buffer, consuming events
int
i
=
0
;
while
(
i
<
nBytes
)
{
Map
<
fileState
>::
iterator
iter
=
state_
.
find
(
label
(
inotifyEvent
.
wd
));
iter
()
=
DELETED
;
}
else
if
(
(
inotifyEvent
.
mask
%
IN_MODIFY
)
||
(
inotifyEvent
.
mask
%
IN_CLOSE_WRITE
)
)
{
Map
<
fileState
>::
iterator
iter
=
state_
.
find
(
label
(
inotifyEvent
.
wd
));
iter
()
=
MODIFIED
;
const
struct
inotify_event
*
inotifyEvent
=
reinterpret_cast
<
const
struct
inotify_event
*>
(
&
buffer
[
i
]
);
// Pout<< "mask:" << inotifyEvent->mask << nl
// << "watchFd:" << inotifyEvent->wd << nl
// << "watchName:" << watchFile_[inotifyEvent->wd] << endl;
if
(
inotifyEvent
->
mask
%
IN_DELETE_SELF
)
{
Map
<
fileState
>::
iterator
iter
=
state_
.
find
(
label
(
inotifyEvent
->
wd
));
iter
()
=
DELETED
;
}
else
if
(
//(inotifyEvent->mask % IN_MODIFY)
(
inotifyEvent
->
mask
%
IN_CLOSE_WRITE
)
)
{
Map
<
fileState
>::
iterator
iter
=
state_
.
find
(
label
(
inotifyEvent
->
wd
));
iter
()
=
MODIFIED
;
}
i
+=
EVENT_SIZE
+
inotifyEvent
->
len
;
}
}
else
{
// No data - reset
watcher_
->
reset
();
// No data
return
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment