cvs: pear /Net_IRC IRC.php
| From: | Tomas V.V.Cox | Date: | Sun, 28 Apr 2002 14:42:22 +0000 |
| Subject: | cvs: pear /Net_IRC IRC.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3604@lists.php.net to get a copy of this message | ||
cox Sun Apr 28 10:42:22 2002 EDT
Modified files:
/pear/Net_IRC IRC.php
Log:
read() uses updateStats() and readEvent() uses updatesEventStats()
Index: pear/Net_IRC/IRC.php
diff -u pear/Net_IRC/IRC.php:1.3 pear/Net_IRC/IRC.php:1.4
--- pear/Net_IRC/IRC.php:1.3 Sun Apr 28 10:24:04 2002
+++ pear/Net_IRC/IRC.php Sun Apr 28 10:42:22 2002
@@ -17,7 +17,7 @@
// | |
// +----------------------------------------------------------------------+
//
-// $Id: IRC.php,v 1.3 2002/04/28 14:24:04 cox Exp $
+// $Id: IRC.php,v 1.4 2002/04/28 14:42:22 cox Exp $
/**
* Class for handling the client side of the IRC protocol (RFC 1459)
@@ -187,6 +187,7 @@
* 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,9 +198,9 @@
}
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 {
@@ -207,6 +208,7 @@
continue;
}
} else {
+ $this->updateStats(true);
$this->log(4, "-> $receive");
}
} while (!$receive);
@@ -340,21 +342,10 @@
*/
// 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 @@
*/
// 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;