* updated send to deal with large data and lots of sends

git-svn-id: svn://netflint.net/xmpphp@48 ef36c318-a008-4979-b6e8-6b496270793b
This commit is contained in:
fritzy 2008-07-16 19:53:24 +00:00
parent 895021132c
commit 513a274ea8

View File

@ -145,6 +145,10 @@ class XMPPHP_XMLStream {
* @var boolean * @var boolean
*/ */
protected $is_server; protected $is_server;
/**
* @var float
*/
protected $last_send = 0;
/** /**
* Constructor * Constructor
@ -537,10 +541,39 @@ class XMPPHP_XMLStream {
* *
* @param string $msg * @param string $msg
*/ */
protected function send($msg) { protected function send($msg, $rec=false) {
#socket_write($this->socket, $msg); if($this->time() - $this->last_send < .1) {
$this->log->log("SENT: $msg", XMPPHP_Log::LEVEL_VERBOSE); usleep(100000);
@fwrite($this->socket, $msg); }
$wait = true;
while($wait) {
$read = null;
$write = array($this->socket);
$except = null;
$select = stream_select($read, $write, $except, 0, 0);
if($select === False) {
$this->doReconnect();
return false;
} elseif ($select > 0) {
$wait = false;
} else {
usleep(100000);
//$this->processTime(.25);
}
}
$sentbytes = @fwrite($this->socket, $msg, 1024);
$this->last_send = $this->time();
$this->log->log("SENT: " . mb_substr($msg, 0, $sentbytes, '8bit'), XMPPHP_Log::LEVEL_VERBOSE);
if($sentbytes === FALSE) {
$this->doReconnect();
} elseif ($sentbytes != mb_strlen($msg, '8bit')) {
$this->send(mb_substr($msg, $sentbytes, mb_strlen($msg, '8bit'), '8bit'), true);
}
}
protected function time() {
list($usec, $sec) = explode(" ", microtime());
return (float)$sec + (float)$usec;
} }
/** /**