Buncha cleanup

This commit is contained in:
Brion Vibber
2010-10-05 13:25:28 -07:00
parent 76353ede54
commit eb04df583a
3 changed files with 148 additions and 29 deletions

View File

@@ -202,13 +202,7 @@ abstract class JsonStreamReader
$lines = explode(self::CRLF, $buffer);
foreach ($lines as $line) {
if ($this->state == 'headers') {
if ($line == '') {
$this->state = 'active';
common_log(LOG_DEBUG, "$this->id connection is active!");
} else {
common_log(LOG_DEBUG, "$this->id read HTTP header: $line");
$this->responseHeaders[] = $line;
}
$this->handleLineHeaders($line);
} else if ($this->state == 'active') {
$this->handleLineActive($line);
}
@@ -219,15 +213,26 @@ abstract class JsonStreamReader
{
// One JSON object on each line...
// Will we always deliver on packet boundaries?
$lines = explode("\n", $buffer);
$lines = explode(self::CRLF, $buffer);
foreach ($lines as $line) {
$this->handleLineActive($line);
}
}
function handleLineActive($line)
function handleLineHeaders($line)
{
if ($line == '') {
$this->state = 'active';
common_log(LOG_DEBUG, "$this->id connection is active!");
} else {
common_log(LOG_DEBUG, "$this->id read HTTP header: $line");
$this->responseHeaders[] = $line;
}
}
function handleLineActive($line)
{
if ($line == "") {
// Server sends empty lines as keepalive.
return;
}
@@ -235,9 +240,9 @@ abstract class JsonStreamReader
if ($data) {
$this->handleJson($data);
} else {
common_log(LOG_ERR, "$this->id received bogus JSON data: " . $line);
common_log(LOG_ERR, "$this->id received bogus JSON data: " . var_export($line, true));
}
}
abstract function handleJson(array $data);
abstract protected function handleJson(array $data);
}