Changeset 1023 -- 2009-07-19 16:23:33
- Author
εγ
δΈηͺ
- Comment
- fixes bigsize packet(thx http://petewarden.typepad.com/searchbrowser/2009/06/how-to-get-tokyo-tyrant-working-in-php.html)
Diffs
Net_TokyoTyrant/trunk/Net/TokyoTyrant.php
@@ -4,6 +4,7 @@
class Net_TokyoTyrantProtocolException extends Net_TokyoTyrantException {};
// License: MIT
+// author: Keita Arai <cocoiti@gmail.com>
class Net_TokyoTyrant
{
@@ -60,7 +61,7 @@
throw new Net_TokyoTyrantNetworkException('socket read eof error');
}
- $result = fread($this->socket, $length);
+ $result = $this->_fullread($this->socket, $length);
if ($result === false) {
throw new Net_TokyoTyrantNetworkException('socket read error');
}
@@ -70,14 +71,36 @@
private function _write($data)
{
- $result = fwrite($this->socket, $data);
+ $result = $this->_fullwrite($this->socket, $data);
if ($result === false) {
throw new Net_TokyoTyrantNetworkException('socket read error');
}
}
+ private function _fullread ($sd, $len) {
+ $ret = '';
+ $read = 0;
+ while ($read < $len && ($buf = fread($sd, $len - $read))) {
+ $read += strlen($buf);
+ $ret .= $buf;
+ }
+ return $ret;
+ }
+
+ private function _fullwrite ($sd, $buf) {
+ $total = 0;
+ $len = strlen($buf);
+
+ while ($total < $len && ($written = fwrite($sd, $buf))) {
+ $total += $written;
+ $buf = substr($buf, $written);
+ }
+
+ return $total;
+ }
+
private function _doRequest($cmd, $values = array())
{
$this->_write($cmd . $this->_makeBin($values));