Skip to content

Commit ebf704e

Browse files
committed
[stream] Don't emit data if empty. Replaced py test with php
1 parent 63925d1 commit ebf704e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Socket/Connection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ public function handleData($stream)
1111
// Socket is raw, not using fread as it's interceptable by filters
1212
// See issues #192, #209, and #240
1313
$data = stream_socket_recvfrom($stream, $this->bufferSize);
14-
if( '' !== $data || false !== $data ){
14+
if ('' !== $data && false !== $data) {
1515
$this->emit('data', array($data, $this));
1616
}
17+
1718
if ('' === $data || false === $data || feof($stream)) {
1819
$this->end();
1920
}

tests/Socket/ServerTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public function testDataWithNoData()
8484
public function testData()
8585
{
8686
$client = stream_socket_client('tcp://localhost:'.$this->port);
87-
87+
8888
fwrite($client, "foo\n");
89-
89+
9090
$mock = $this->createCallableMock();
9191
$mock
9292
->expects($this->once())
@@ -99,25 +99,26 @@ public function testData()
9999
$this->loop->tick();
100100
$this->loop->tick();
101101
}
102-
102+
103103
/**
104104
* Test data sent from python language
105-
*
105+
*
106106
* @covers React\EventLoop\StreamSelectLoop::tick
107107
* @covers React\Socket\Connection::handleData
108108
*/
109109
public function testDataSentFromPy()
110110
{
111-
$cmd = "python -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);s.connect((\"127.0.0.1\", $this->port));s.sendall(\"foo\\n\");s.shutdown(1);'";
112-
exec($cmd);
113-
111+
$client = stream_socket_client('tcp://localhost:' . $this->port);
112+
fwrite($client, "foo\n");
113+
stream_socket_shutdown($client, STREAM_SHUT_WR);
114+
114115
$mock = $this->createCallableMock();
115116
$mock
116117
->expects($this->once())
117118
->method('__invoke')
118119
->with("foo\n");
119120

120-
121+
121122
$this->server->on('connection', function ($conn) use ($mock) {
122123
$conn->on('data', $mock);
123124
});

0 commit comments

Comments
 (0)