Skip to content

Commit

Permalink
Fix memory increase
Browse files Browse the repository at this point in the history
  • Loading branch information
laogui committed Mar 27, 2017
1 parent 84ffc78 commit 19664e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function close($callback = null)
$this->state = self::STATE_CLOSED;
$this->emit('end', [$this]);
$this->emit('close', [$this]);
if ($callback) {
if (is_callable($callback)) {
$callback($this);
}
});
Expand Down
12 changes: 11 additions & 1 deletion src/Protocal/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function parse($data, $stream)
}
}
}
$this->skip($this->pctSize - $len + $this->length());
$this->restBuffer($this->pctSize - $len + $this->length());
goto packet;
}

Expand Down Expand Up @@ -367,6 +367,16 @@ public function skip($len)
$this->bufferPos += $len;
}

public function restBuffer($len)
{
if(strlen($this->buffer) === ($this->bufferPos+$len)){
$this->buffer = '';
}else{
$this->buffer = substr($this->buffer,$this->bufferPos+$len);
}
$this->bufferPos = 0;
}

public function length()
{
return strlen($this->buffer) - $this->bufferPos;
Expand Down

0 comments on commit 19664e9

Please sign in to comment.