<commit_before><?php

/**
 * A Pheanstalk_Socket implementation around a fsockopen() stream.
 *
 * @author <NAME>
 * @package Pheanstalk
 * @licence http://www.opensource.org/licenses/mit-license.php
 */
class Pheanstalk_Socket_NativeSocket implements Pheanstalk_Socket
{
	/**
	 * The default timeout for a blocking read on the socket
	 */
	const SOCKET_TIMEOUT = 1;

	/**
	 * Number of retries for attempted writes which return zero length.
	 */
	const WRITE_RETRIES = 8;

	private $_socket;

	/**
	 * @param string $host
	 * @param int $port
	 * @param int $connectTimeout
	 */
	public function __construct($host, $port, $connectTimeout)
	{
		$this->_socket = $this->_wrapper()
			->fsockopen($host, $port, $errno, $errstr, $connectTimeout);

		if (!$this->_socket)
		{
			throw new Pheanstalk_Exception_ConnectionException($errno, $errstr);
		}

		$this->_wrapper()
			->stream_set_timeout($this->_socket, self::SOCKET_TIMEOUT);
	}

	/* (non-phpdoc)
	 * @see Pheanstalk_Socket::write()
	 */
	public function write($data)
	{
		$history = new Pheanstalk_Socket_WriteHistory(self::WRITE_RETRIES);

		for ($written = 0, $fwrite = 0; $written < strlen($data); $written += $fwrite)
		{
			$fwrite = $this->_wrapper()
				->fwrite($this->_socket, substr($data, $written));

			$history->log($fwrite);

			if ($history->isFullWithNoWrites())
			{<commit_msg>Provide host info on queue connection failures.<commit_after><?php

/**
 * A Pheanstalk_Socket implementation around a fsockopen() stream.
 *
 * @author <NAME>
 * @package Pheanstalk
 * @licence http://www.opensource.org/licenses/mit-license.php
 */
class Pheanstalk_Socket_NativeSocket implements Pheanstalk_Socket
{
	/**
	 * The default timeout for a blocking read on the socket
	 */
	const SOCKET_TIMEOUT = 1;

	/**
	 * Number of retries for attempted writes which return zero length.
	 */
	const WRITE_RETRIES = 8;

	private $_socket;

	/**
	 * @param string $host
	 * @param int $port
	 * @param int $connectTimeout
	 */
	public function __construct($host, $port, $connectTimeout)
	{
		$this->_socket = $this->_wrapper()
			->fsockopen($host, $port, $errno, $errstr, $connectTimeout);

		if (!$this->_socket)
		{
			throw new Pheanstalk_Exception_ConnectionException($errno, $errstr . " (connecting to $host:$port)");
		}

		$this->_wrapper()
			->stream_set_timeout($this->_socket, self::SOCKET_TIMEOUT);
	}

	/* (non-phpdoc)
	 * @see Pheanstalk_Socket::write()
	 */
	public function write($data)
	{
		$history = new Pheanstalk_Socket_WriteHistory(self::WRITE_RETRIES);

		for ($written = 0, $fwrite = 0; $written < strlen($data); $written += $fwrite)
		{
			$fwrite = $this->_wrapper()
				->fwrite($this->_socket, substr($data, $written));

			$history->log($fwrite);

			if ($history->isFullWithNoWrites())
			{
{'fraction_non_alphanumeric': 0.15254237288135594, 'fraction_numerical': 0.00288496213487198, 'mean_word_length': 4.175373134328358, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1875155', 'n_tokens_mistral': 1001, 'n_tokens_neox': 914, 'n_words': 213}