<commit_before>RFC 0072: Initialization and Interrupts of ServerProtocols
========================================================================
$Id$

@authors: gellweiler
@created: Tue Sep 12 15:27:01 CEST 2006
@status: draft
@category: peer.server

Scope of Change
---------------
peer.server.Server classes will call 2 additional protocol methods 
to initialize protocol and to handle idle times.

Rationale
---------
Need to initialize protocol and update protocol data
in intervals between client connects.

Functionality
-------------

Refactoring of peer.server.PreforkingServer will provide a
method handleChild():

<?php
  /**
   * Handle a forked child
   *
   * @access  protected
   */
  function handleChild() {

    // Handle initialization of protocol. This
    // is called once for every new child created
    if (FALSE === $this->protocol->initialize()) return;

    $requests= 0;
    while ($requests < $this->maxrequests) {
      try(); {

        $timeout= time() + $this->timeout;
        while (time() < $timeout) {
          $m= &$this->socket->accept();
          usleep(1);
        }
      } if (catch('IOException', $e)) {
        $this->cat && $this->cat->warn('Child', getmypid(), 'in accept ~', $e);
        exit(-1);
      }

      // Handle idle loop of protocol.
      if (!$m) {
        if (FALSE === $this->protocol->handleIdle()) return;
        continue;
      }

      // ...
      // Handle client connect
    }
  }
?>

The initialize method of the protocol will be called on start of the process,
e.g. in peer.server.ForkingServer and PreforkingServer everytime a child is
forked. After a given timout when no incoming connections could be accepted, 
the Server calls a method handleIdle(). This provides the possibility to interrupt
idle times while waiting on client connects.

Security considerations
-----------------------
n/a

Speed impact
------------
n/a

Dependencies
------------
n/a

Related documents
-----------------
- http://experiments.xp-framework.net/?arena,peking
  Experiment


Comments
--------
- gellweiler, Tue Sep 12 15:45:59 CEST 2006
  The method names should be discussed. Currently there is only 
  an implementation for peer.server.PreforkingServer in
  http://experiments.xp-framework.net/?arena,peking,peer,server/PreforkingServer.class.php

<EOF><commit_msg>- Add comment on initialize() and idle() - Enable $Id$ expansion<commit_after>RFC 0072: Initialization and Interrupts of ServerProtocols
========================================================================
$Id$

@authors: gellweiler
@created: Tue Sep 12 15:27:01 CEST 2006
@status: draft
@category: peer.server

Scope of Change
---------------
peer.server.Server classes will call 2 additional protocol methods 
to initialize protocol and to handle idle times.

Rationale
---------
Need to initialize protocol and update protocol data
in intervals between client connects.

Functionality
-------------

Refactoring of peer.server.PreforkingServer will provide a
method handleChild():

<?php
  /**
   * Handle a forked child
   *
   * @access  protected
   */
  function handleChild() {

    // Handle initialization of protocol. This
    // is called once for every new child created
    if (FALSE === $this->protocol->initialize()) return;

    $requests= 0;
    while ($requests < $this->maxrequests) {
      try(); {

        $timeout= time() + $this->timeout;
        while (time() < $timeout) {
          $m= &$this->socket->accept();
          usleep(1);
        }
      } if (catch('IOException', $e)) {
        $this->cat && $this->cat->warn('Child', getmypid(), 'in accept ~', $e);
        exit(-1);
      }

      // Handle idle loop of protocol.
      if (!$m) {
        if (FALSE === $this->protocol->handleIdle()) return;
        continue;
      }

      // ...
      // Handle client connect
    }
  }
?>

The initialize method of the protocol will be called on start of the process,
e.g. in peer.server.ForkingServer and PreforkingServer everytime a child is
forked. After a given timout when no incoming connections could be accepted, 
the Server calls a method handleIdle(). This provides the possibility to interrupt
idle times while waiting on client connects.

Security considerations
-----------------------
n/a

Speed impact
------------
n/a

Dependencies
------------
n/a

Related documents
-----------------
- http://experiments.xp-framework.net/?arena,peking
  Experiment


Comments
--------
- gellweiler, Tue Sep 12 15:45:59 CEST 2006
  The method names should be discussed. Currently there is only 
  an implementation for peer.server.PreforkingServer in
  http://experiments.xp-framework.net/?arena,peking,peer,server/PreforkingServer.class.php

- friebe, Wed Sep 13 14:19:51 CEST 2006
  initialize() is OK, though I think it should be complemented by a
  finalize() method. In addition, I think it would be benefitial to
  make these optional (e.g., by adding an additional interface called
  Initializable).
  I don't especially like the idle() method, which is called 
  "sporadically" - non-deterministic, in other words.

<EOF>
{'fraction_non_alphanumeric': 0.16581632653061223, 'fraction_numerical': 0.014913657770800628, 'mean_word_length': 2.750551876379691, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6134839', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1369, 'n_words': 504}