Skip to content

LibEventLoop and large messages #26

@mbonneau

Description

@mbonneau

I ran into an issue when sending messages that are larger than the bufferSize in Stream (4096).

It appears that if the size of the data in the underlying stream is larger than the buffer, handleData only gets called once. The data remains there until there is another read event triggered on the stream.

I wrote something to reproduce it:

<?php
require_once __DIR__ . "/vendor/autoload.php";

$loop = \React\EventLoop\Factory::create();

list($sockA, $sockB) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);

$streamA = new \React\Stream\Stream($sockA, $loop);
$streamB = new \React\Stream\Stream($sockB, $loop);

$testString = str_repeat("*", $streamA->bufferSize + 1);

$i = 0;
$buffer = "";
$streamB->on('data', function ($data, $streamB) use (&$i, &$buffer, &$testString) {
    $i++;
    $buffer .= $data;
    echo "Call " . $i . ": " . strlen($data) . " bytes - buffer is " . strlen($buffer) . " bytes\n";
    if (strlen($testString) == strlen($buffer)) {
        $streamB->close();
    }
});

$streamA->on('close', function ($streamA) {
    $streamA->close();
});

$streamA->write($testString);

$loop->run();

With StreamSelectLoop, I get the results I expect:

Call 1: 4096 bytes - buffer is 4096 bytes
Call 2: 1 bytes - buffer is 4097 bytes

With LibEventLoop:

Call 1: 4096 bytes - buffer is 4096 bytes

And then it hangs.

I have run this test with the same results on Mac OS 10.10.2 with php 5.6.5 and also on Centos 6.5 with 5.5.20.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions