My problem is that I use inotify to watch multiple directories and I use read() function to read any changes. My point is that I cant watch all of this directories in "same time" ("for" loop), because read() function stop program until something happens to currently watched directory.
There is simplified "main" code:
while (1){
for(int i = 0; i < numberOfDirectories; i++){
string fileEnd = get_event(fd[i], catalogs[i]).c_str());
if(string != "") do some code;
}
sleep(1);
}
Where get_event return path to changed file, fd[i] is instance of inotify, catalogs[i] contain name of watched directory.
And there is some code of get_even func:
#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
string get_event(int fd, string target)
{
ssize_t len;
char buff[BUFF_SIZE] = {0};
len = read (fd, buff, BUFF_SIZE);
At this point main "for" loop stop work and wait until something happens in first directory. I want to just check is there any changes in watched directory instead of waiting for changes.
Help :<