Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2004, Roxen IS.   //   // The Roxen WebServer main program.   //   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.974 2010/05/06 13:21:08 noring Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.975 2010/05/11 13:14:47 grubba Exp $";      //! @appears roxen   //!   //! The Roxen WebServer main program.      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN
Roxen.git/server/base_server/roxen.pike:1178:      class BackgroundProcess   //! A class to do a task repeatedly in the background, in a way that   //! makes as little impact as possible on the incoming requests (using   //! @[background_run]).   //!   //! The user must keep a reference to this object, otherwise it will remove   //! itself and the callback won't be called anymore.   {    int|float period; +  function func; +  array args;    int stopping = 0;       static void repeat (function func, mixed args)    {    // Got a minimum of four refs to this:    // o One in the task array in bg_process_queue.    // o One on the stack in the call in bg_process_queue.    // o One as current_object in the stack frame.    // o One on the stack as argument to _refs.    int self_refs = _refs (this);   #ifdef DEBUG    if (self_refs < 4)    error ("Minimum ref calculation wrong - have only %d refs.\n", self_refs);   #endif -  if (stopping || (self_refs <= 4) || !func) return; +  if (stopping || (self_refs <= 4) || !func) { +  stopping = 2; // Stopped. +  return; +  }    mixed err = catch {    func (@args);    };    if (err) {    catch {    report_error(LOC_M(66, "Uncaught error in background process:") +    "%s\n", describe_backtrace(err));    };    }    background_run (period, repeat, func, args);
Roxen.git/server/base_server/roxen.pike:1221:    }       //! @decl static void create (int|float period, function func, mixed... args);    //!    //! The function @[func] will be called with the following arguments    //! after approximately @[period] seconds, and then kept being    //! called with approximately that amount of time between each call.    //!    //! The repetition will stop if @[stop] is called, or if @[func]    //! throws an error. -  static void create (int|float period_, function func, mixed... args) +  static void create (int|float period_, function func_, mixed... args_)    {    period = period_; -  +  func = func_; +  args = args_;    background_run (period, repeat, func, args);    }       void stop()    //! Sets a flag to stop the succession of calls.    { -  stopping = 1; +  stopping |= 1;    }    -  +  void start() +  //! Restart a stopped process. +  { +  int state = stopping; +  stopping = 0; +  if (state & 2) { +  background_run (period, repeat, func, args); +  } +  } +     string _sprintf() {return "BackgroundProcess()";}   }         mapping get_port_options( string key )   //! Get the options for the key 'key'.   //! The intepretation of the options is protocol specific.   {    return (query( "port_options" )[ key ] || ([]));   }