Archived
1
0
Fork 0

notify/inotify.c: improved notify_read()

This commit is contained in:
Henrik Hautakoski 2010-09-26 16:49:43 +02:00
parent c6f346586e
commit d05c15a935
2 changed files with 24 additions and 15 deletions

1
TODO
View file

@ -3,5 +3,4 @@
TODO LIST
##################
* Use queue in inotify_read(), tree and remove indexer
* fix mysql module

View file

@ -217,16 +217,17 @@ int notify_rm_watch(const char *path) {
notify_event* notify_read() {
char buf[INOBUFSIZE];
/* bytes ready on the inotify descriptor */
int ioready;
/* if we don't have pending events, wait for more data on fd */
if (queue_isempty(event_queue)) {
/* time resolution */
struct timespec tres = { 0, 2000000 };
unsigned short tcount;
/* bytes ready on the inotify descriptor */
int ioready;
for(tcount = 0; tcount < 10; tcount++) {
if (ioctl(fd, FIONREAD, &ioready) == -1)
@ -237,12 +238,21 @@ notify_event* notify_read() {
nanosleep(&tres, NULL);
}
}
/* otherwise, only read if the data available at
this given moment is "large enough" */
else {
ioctl(fd, FIONREAD, &ioready);
if (ioready < INOBUFSIZE / 2)
ioready = 0;
}
/* read if we have data on fd */
while(ioready > 0) {
dprint("%i bytes avail\n", ioready);
char buf[INOBUFSIZE];
int offset = 0, rbytes = read(fd, buf, INOBUFSIZE);
if (rbytes == -1)