pike.git / lib / modules / Filesystem.pmod / Monitor.pmod / basic.pike

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:1:   //   // Basic filesystem monitor.   // - // $Id: basic.pike,v 1.7 2009/07/15 16:11:44 grubba Exp $ + // $Id: basic.pike,v 1.8 2009/07/15 16:28:52 grubba Exp $   //   // 2009-07-09 Henrik Grubbström   //      //! Basic filesystem monitor.   //!   //! This module is intended to be used for incremental scanning of   //! a filesystem.      //! The default maximum number of seconds between checks of directories
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:174:    int `==(mixed m) { return next_poll == m; }       protected string _sprintf(int c)    {    return sprintf("Monitor(%O, %O, next: %s, st: %O)",    path, flags, ctime(next_poll) - "\n", st);    }   }      //! Mapping from monitored path to corresponding @[Monitor]. + //! + //! The paths are normalized to @expr{combine_path(path, ".")@}, + //! i.e. no trailing slashes. + //! + //! @note + //! All filesystems are handled as if case-sensitive. This should + //! not be a problem for case-insensitive filesystems as long as + //! case is maintained.   protected mapping(string:Monitor) monitors = ([]);      //! Heap containing all active @[Monitor]s.   //!   //! The heap is sorted on @[Monitor()->next_poll].   protected ADT.Heap monitor_queue = ADT.Heap();      //! Create a new monitor.   //!   //! @param max_dir_check_interval
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:208:   }      //! Clear the set of monitored files and directories.   void clear()   {    monitors = ([]);    monitor_queue = ADT.Heap();   }      //! Calculate a suitable time for the next poll of this monitor. + //! + //! @param m + //! Monitor to update. + //! + //! @param st + //! New stat for the monitor. + //! + //! This function is called by @[check_monitor()] to schedule the + //! next check.   protected void update_monitor(Monitor m, Stdio.Stat st)   {    int delta = m->max_dir_check_interval;    m->st = st;    if (!st || !st->isdir) {    delta *= m->file_interval_factor;    }    if (st) {    int d = 1 + ((time(1) - st->mtime)>>4);    if (d < 0) d = m->max_dir_check_interval;
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:524:   //! or when @[max_wait] has expired.   //!   //! @note   //! Any callbacks will be called from the same thread as the one   //! calling @[check()].   //!   //! @seealso   //! @[monitor()]   void check(int|void max_wait)   { -  if (!sizeof(monitors)) { -  if (max_wait > 0) sleep(max_wait); -  return; -  } +     while(1) {    int cnt;    int t = time();    Monitor m; -  +  if (sizeof(monitors)) {    while ((m = monitor_queue->peek()) &&    m <= t) {    cnt += check_monitor(m);    } -  +  }    if (cnt || !max_wait) return;    if (max_wait > 0) max_wait--;    sleep(1);    }   }      //! Backend to use.   //!   //! If @expr{0@} (zero) - use the default backend.   protected Pike.Backend backend;