Only strip newline in OrderedStreamingForkController

The controller should pass through lines of input exactly as
they were provided, only stripping the trailing newline that
delimits items. The trim was making `door` and `door ` equivilant
but for the use case in search the distinction is important.

Additionally check that the line is actually empty, don't throw
away inputs like '0' which are falsy.

Change-Id: Ifac910543fdb46a27da021e831e3e18befefcfc5
This commit is contained in:
Erik Bernhardson 2018-09-28 10:58:00 -07:00
parent e2e9117a51
commit c94dea7029

View file

@ -134,9 +134,12 @@ class OrderedStreamingForkController extends ForkController {
*/ */
protected function consumeNoFork() { protected function consumeNoFork() {
while ( !feof( $this->input ) ) { while ( !feof( $this->input ) ) {
$line = trim( fgets( $this->input ) ); $data = fgets( $this->input );
if ( $line ) { if ( $data[ strlen( $data ) - 1 ] == "\n" ) {
$result = call_user_func( $this->workCallback, $line ); $data = substr( $data, 0, -1 );
}
if ( strlen( $data ) !== 0 ) {
$result = call_user_func( $this->workCallback, $data );
fwrite( $this->output, "$result\n" ); fwrite( $this->output, "$result\n" );
} }
} }
@ -160,8 +163,12 @@ class OrderedStreamingForkController extends ForkController {
$this->updateAvailableSockets( $sockets, $used, $sockets ? 0 : 5 ); $this->updateAvailableSockets( $sockets, $used, $sockets ? 0 : 5 );
} while ( !$sockets ); } while ( !$sockets );
} }
$data = trim( $data ); // Strip the trailing \n. The last line of a file might not have a trailing
if ( !$data ) { // \n though
if ( $data[ strlen( $data ) - 1 ] == "\n" ) {
$data = substr( $data, 0, -1 );
}
if ( strlen( $data ) === 0 ) {
continue; continue;
} }
$socket = array_pop( $sockets ); $socket = array_pop( $sockets );