Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions generated/sockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,36 +753,6 @@ function socket_shutdown($socket, int $how = 2): void
}


/**
* The function socket_write writes to the
* socket from the given
* buffer.
*
* @param resource $socket
* @param string $buffer The buffer to be written.
* @param int $length The optional parameter length can specify an
* alternate length of bytes written to the socket. If this length is
* greater than the buffer length, it is silently truncated to the length
* of the buffer.
* @return int Returns the number of bytes successfully written to the socket.
* The error code can be retrieved with
* socket_last_error. This code may be passed to
* socket_strerror to get a textual explanation of the
* error.
* @throws SocketsException
*
*/
function socket_write($socket, string $buffer, int $length = 0): int
{
error_clear_last();
$result = \socket_write($socket, $buffer, $length);
if ($result === false) {
throw SocketsException::createFromPhpError();
}
return $result;
}


/**
* Exports the WSAPROTOCOL_INFO structure into shared memory and returns
* an identifier to be used with socket_wsaprotocol_info_import. The
Expand Down
1 change: 1 addition & 0 deletions generator/config/specialCasesFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'preg_replace',
'openssl_encrypt',
'readdir',
'socket_write',
];
30 changes: 30 additions & 0 deletions lib/special_cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Safe;

use Safe\Exceptions\SocketsException;
use const PREG_NO_ERROR;
use Safe\Exceptions\ApcException;
use Safe\Exceptions\ApcuException;
Expand Down Expand Up @@ -209,3 +210,32 @@ function openssl_encrypt(string $data, string $method, string $key, int $options
}
return $result;
}

/**
* The function socket_write writes to the
* socket from the given
* buffer.
*
* @param resource $socket
* @param string $buffer The buffer to be written.
* @param int $length The optional parameter length can specify an
* alternate length of bytes written to the socket. If this length is
* greater than the buffer length, it is silently truncated to the length
* of the buffer.
* @return int Returns the number of bytes successfully written to the socket.
* The error code can be retrieved with
* socket_last_error. This code may be passed to
* socket_strerror to get a textual explanation of the
* error.
* @throws SocketsException
*
*/
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;
}