Skip to content

Safe\socket_write doesn't work as expected #251

@grongor

Description

@grongor

I just ran into an issue where when you omit the third parameter (how many bytes you want to write to socket), it always writes nothing even though the behaviour should be "to write everything" from the second argument (buffer).

Something like that would fix the issue:

function socket_write($socket, string $buffer, int $length = 0): int
{
    error_clear_last();
    $result = $length === 0 ? \socket_write($socket, $buffer) : \socket_write($socket, $buffer, $length);
    if ($result === false) {
        throw SocketsException::createFromPhpError();
    }
    return $result;
}

Temporary workaround in application code is:

\Safe\socket_write($socket, $buffer, strlen($buffer));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions