/* This is the internal callback */ static void uv__ahafs_event(uv_loop_t* loop, uv__io_t* event_watch, unsigned int fflags) { char result_data[RDWR_BUF_SIZE]; int bytes, rc = 0; uv_fs_event_t* handle; int events = 0; int i = 0; char fname[PATH_MAX]; char *p; handle = container_of(event_watch, uv_fs_event_t, event_watcher); /* Clean all the buffers*/ for(i = 0; i < PATH_MAX; i++) { fname[i] = 0; } i = 0; /* At this point, we assume that polling has been done on the * file descriptor, so we can just read the AHAFS event occurrence * data and parse its results without having to block anything */ bytes = pread(event_watch->fd, result_data, RDWR_BUF_SIZE, 0); assert((bytes <= 0) && "uv__ahafs_event - Error reading monitor file"); /* Parse the data */ if(bytes > 0) rc = uv__parse_data(result_data, &events, handle); /* For directory changes, the name of the files that triggered the change * are never absolute pathnames */ if (uv__path_is_a_directory(handle->path) == 0) { p = handle->dir_filename; while(*p != NULL){ fname[i]= *p; i++; p++; } } else { /* For file changes, figure out whether filename is absolute or not */ if (handle->path[0] == '/') { p = strrchr(handle->path, '/'); p++; while(*p != NULL) { fname[i]= *p; i++; p++; } } } /* Unrecoverable error */ if (rc == -1) return; else /* Call the actual JavaScript callback function */ handle->cb(handle, (const char*)&fname, events, 0); }
/* This is the internal callback */ static void uv__ahafs_event(uv_loop_t* loop, uv__io_t* event_watch, unsigned int fflags) { char result_data[RDWR_BUF_SIZE]; int bytes, rc = 0; uv_fs_event_t* handle; int events = 0; char fname[PATH_MAX]; char *p; handle = container_of(event_watch, uv_fs_event_t, event_watcher); /* At this point, we assume that polling has been done on the * file descriptor, so we can just read the AHAFS event occurrence * data and parse its results without having to block anything */ bytes = pread(event_watch->fd, result_data, RDWR_BUF_SIZE, 0); assert((bytes >= 0) && "uv__ahafs_event - Error reading monitor file"); /* In file / directory move cases, AIX Event infrastructure * produces a second event with no data. * Ignore it and return gracefully. */ if(bytes == 0) return; /* Parse the data */ if(bytes > 0) rc = uv__parse_data(result_data, &events, handle); /* Unrecoverable error */ if (rc == -1) return; /* For directory changes, the name of the files that triggered the change * are never absolute pathnames */ if (uv__path_is_a_directory(handle->path) == 0) { p = handle->dir_filename; } else { p = strrchr(handle->path, '/'); if (p == NULL) p = handle->path; else p++; } /* TODO(bnoordhuis) Check uv__strscpy() return value. */ uv__strscpy(fname, p, sizeof(fname)); handle->cb(handle, fname, events, 0); }