<commit_before><?php
/**
* Octave-daemon -- a network daemon for Octave, written in PHP
*
* Copyright (C) 2011 <NAME> <<EMAIL>>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
*
* @package octave-daemon-server
* @author <NAME> <<EMAIL>>
* @version 1.0
* @copyright Copyright (c) 2011, <NAME>
* @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero GPL
*/

/**
* This class manages the {@link Octave_client_socket client connections} and {@link Octave_controller controller} pool.
*
* @package octave-daemon-server
*/
class Octave_pool
{

	static private $pool=array();
	static public $maxCount=2;
	static public $noChild=false;
	static private $pending_connections=array();

	private function __construct()
	{
	}

	public function getChild($cSocket)
	{
		if (count(self::$pool)<self::$maxCount)
			return self::registerChild($cSocket);
		return self::firstChild($cSocket);
	}

	private function registerChild($cSocket)
	{
		$controller=new Octave_controller();
		$controller->init();
		$kid=new Octave_client_socket($controller);
		$kid->initSocket($cSocket);
		self::$pool[]=$kid;
		return $kid;
	}

	private function firstChild($cSocket)
	{
		foreach(self::$pool as $kid) {
			if ($kid->busy())
				continue;
			$kid->initSocket($cSocket);
			return $kid;
		}
		return self::$noChild;
	}

	public function deadChild($sig)
	{
		$pid=pcntl_waitpid(-1,$status);
		foreach(self::$pool as $kid)
			if ($kid->processFuneral($pid))
				break;
	}

	public function newConnection($socket)
	{
		self::$pending_connections[]=$socket;
	}<commit_msg>Improved pool management (reusing children if available)<commit_after><?php
/**
* Octave-daemon -- a network daemon for Octave, written in PHP
*
* Copyright (C) 2011 <NAME> <<EMAIL>>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
*
* @package octave-daemon-server
* @author <NAME> <<EMAIL>>
* @version 1.0
* @copyright Copyright (c) 2011, <NAME>
* @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero GPL
*/

/**
* This class manages the {@link Octave_client_socket client connections} and {@link Octave_controller controller} pool.
*
* @package octave-daemon-server
*/
class Octave_pool
{
	static private $pool=array();
	static public $maxCount=2;
	static private $pending_connections=array();

	private function __construct()
	{
	}

	public function getChild($cSocket)
	{
		if ($kid=self::firstChild($cSocket))
			return $kid;

		if (count(self::$pool)<self::$maxCount)
			return self::registerChild($cSocket);

		return false;
	}

	private function registerChild($cSocket)
	{
		$controller=new Octave_controller();
		$controller->init();
		$kid=new Octave_client_socket($controller);
		$kid->initSocket($cSocket);
		self::$pool[]=$kid;
		return $kid;
	}

	private function firstChild($cSocket)
	{
		foreach(self::$pool as $kid) {
			if ($kid->busy())
				continue;
			$kid->initSocket($cSocket);
			return $kid;
		}
	}

	public function deadChild($sig)
	{
		$pid=pcntl_waitpid(-1,$status);
		foreach(self::$pool as $kid)
			if ($kid->processFuneral($pid))
				break;
	}

	public function newConnection($socket)
	{
		self::$pending_connections[]=$socket;
	}
{'fraction_non_alphanumeric': 0.1281638288080994, 'fraction_numerical': 0.006902899217671422, 'mean_word_length': 4.609032258064516, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '4026873', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1349, 'n_words': 437}