Index: RPC.php =================================================================== RCS file: /repository/pear/XML_RPC/RPC.php,v retrieving revision 1.17 diff -u -r1.17 RPC.php --- RPC.php 11 Oct 2003 22:32:16 -0000 1.17 +++ RPC.php 2 Dec 2003 06:28:40 -0000 @@ -428,11 +428,23 @@ $msg->debug = $this->debug; return $this->sendPayloadHTTP10($msg, $this->server, $this->port, $timeout, $this->username, - $this->password); + $this->password,0); + } + + function sendNonBlocking($msg, $timeout=0) + { + // by Norman Elton - elnormo@hotmail.com + + // Send request, return immediately + // where msg in an xmlrpcmsg + $msg->debug=$this->debug; + return $this->sendPayloadHTTP10($msg, $this->server, $this->port, + $timeout, $this->username, + $this->password,1); } function sendPayloadHTTP10($msg, $server, $port, $timeout=0, - $username = "", $password = "") + $username = "", $password = "", $nonblocking=0) { // If we're using a proxy open a socket to the proxy server instead to the xml-rpc server if ($this->proxy){ @@ -463,6 +475,8 @@ XML_RPC_ERROR_CONNECTION_FAILED); } + stream_set_blocking($fp,!$nonblocking); + // Only create the payload if it was not created previously if (empty($msg->payload)) { $msg->createPayload(); @@ -504,12 +518,53 @@ $this->errstr = "Write error"; return 0; } - $resp = $msg->parseResponseFile($fp); - fclose($fp); - return $resp; + + if ($nonblocking == 0) { + $resp=$msg->parseResponseFile($fp); + fclose($fp); + return $resp; + } else { + stream_set_blocking($fp,0); + return new XML_RPC_NonBlocking($fp,$msg); + } } } +// by Norman Elton - wnelto@net.wm.edu +class XML_RPC_NonBlocking extends XML_RPC_Base +{ + var $fp; + var $msg; + var $mesg_cache = ""; + + function XML_RPC_NonBlocking($fp,$msg) + { + $this->fp = $fp; + $this->msg = $msg; + } + + function ready() + { + $mesg_buffer = fread($this->fp,32768); + while ($mesg_buffer != "") { + $this->mesg_cache .= $mesg_buffer; + $mesg_buffer = fread($this->fp,32768); + } + return feof($this->fp); + } + + function recv() + { + if (!feof($this->fp)) { + stream_set_blocking($this->fp,1); + while (!feof($this->fp)) { + $resp_text = fread($this->fp,32768); + $this->mesg_cache .= $resp_text; + } + } + return $this->msg->parseResponse($this->mesg_cache); + } +} class XML_RPC_Response extends XML_RPC_Base {