Permalink
Browse files

read() uses updateStats() and readEvent() uses updatesEventStats()

git-svn-id: http://svn.php.net/repository/pear/packages/Net_IRC/trunk@80273 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent bd384bb commit 263bbbafa63655dc844a8a417a5ea801d29806e2 @tvvcox tvvcox committed Apr 28, 2002
Showing with 16 additions and 16 deletions.
  1. +16 −16 IRC.php
View
@@ -187,6 +187,7 @@ function write($command)
* Reads from the socket
*
* @param bool $once Wait until there is info to read
+ * @return mixed False on socket error, null on no data, string the data
*/
function read($block = false)
{
@@ -197,16 +198,17 @@ function read($block = false)
}
do {
$receive = rtrim(fgets($this->socket, 1024));
- // XXX Only update stats for example each 2 seconds
- $this->updateStats();
if (!$receive) {
+ // XXX Only update stats for example each 2 seconds
+ $this->updateStats(false);
if (!$block) {
return null;
} else {
usleep(500000); // Half second is enough interactive
continue;
}
} else {
+ $this->updateStats(true);
$this->log(4, "-> $receive");
}
} while (!$receive);
@@ -340,21 +342,10 @@ function callback($command, $params = array())
*/
// XXX rename to _updateStats()
// XXX Introduce stats levels (none, normal, full)
- function updateStats($event = null, $args = array())
+ function updateStats($data)
{
- if ($event) {
+ if ($data) {
$this->stats['rx_idle'] = 0;
-
- if (isset($this->stats['events'][$event])) {
- $item = &$this->stats['events'][$event];
- $this->log(5, "Updating event $event");
- $this->updateEventStats($item, $args);
- } else {
- $this->stats['events'][$event] = array();
- $this->stats['events'][$event]['times'] = 1;
- $this->stats['events'][$event]['interval'] = 1;
- $this->stats['events'][$event]['last'] = time();
- }
} else {
$this->stats['rx_idle'] += time() - $this->stats['last_updated'];
$this->log(6, "Updating idle time to: " . $this->stats['rx_idle']);
@@ -369,8 +360,17 @@ function updateStats($event = null, $args = array())
*/
// XXX This should be enhanced to be able to track the different
// kinds of flood attacks (maybe in a different class)
- function updateEventStats(&$event, $args = array())
+ function updateEventStats($event, $args = array())
{
+ $this->log(5, "Updating event $event");
+ if (!isset($this->stats['events'][$event])) {
+ $this->stats['events'][$event] = array();
+ $this->stats['events'][$event]['times'] = 1;
+ $this->stats['events'][$event]['interval'] = 1;
+ $this->stats['events'][$event]['last'] = time();
+ return;
+ }
+ $event = &$this->stats['events'][$event];
$event['times'] += 1;
// XXX make a configurable param
$int = 60;

0 comments on commit 263bbba

Please sign in to comment.