Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit db190ca

Browse files
committed
Introduce read flags (PEEK and OOB).
We introduce two new constants: * `READ_OUT_OF_BAND`, * `READ_PEEK`. And we allow to use them in the `Hoa\Socket\Connection::read` method only.
1 parent c851694 commit db190ca

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

Connection/Connection.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ abstract class Connection
5555
Stream\IStream\Pathable,
5656
\Iterator
5757
{
58+
/**
59+
* Read data out-of-band.
60+
*
61+
* @const int
62+
*/
63+
const READ_OUT_OF_BAND = STREAM_OOB;
64+
65+
/**
66+
* Read data but do not consume them.
67+
*
68+
* @const int
69+
*/
70+
const READ_PEEK = STREAM_PEEK;
71+
5872
/**
5973
* Socket.
6074
*
@@ -615,11 +629,12 @@ public function getRemoteAddress()
615629
* Warning: if this method returns false, it means that the buffer is empty.
616630
* You should use the Hoa\Stream::setStreamBlocking(true) method.
617631
*
618-
* @param int $length Length.
632+
* @param int $length Length.
633+
* @param int $flags Flags.
619634
* @return string
620635
* @throws \Hoa\Socket\Exception
621636
*/
622-
public function read($length)
637+
public function read($length, $flags = 0)
623638
{
624639
if (null === $this->getStream()) {
625640
throw new Socket\Exception(
@@ -642,13 +657,13 @@ public function read($length)
642657
}
643658

644659
if (false === $this->isRemoteAddressConsidered()) {
645-
return stream_socket_recvfrom($this->getStream(), $length);
660+
return stream_socket_recvfrom($this->getStream(), $length, $flags);
646661
}
647662

648663
$out = stream_socket_recvfrom(
649664
$this->getStream(),
650665
$length,
651-
0,
666+
$flags,
652667
$address
653668
);
654669
$this->_remoteAddress = !empty($address) ? $address : null;

0 commit comments

Comments
 (0)