<commit_before><?php

namespace React\Socket;

use Evenement\EventEmitter;
use React\EventLoop\LoopInterface;

class Connection extends EventEmitter implements ConnectionInterface
{
    public $bufferSize = 4096;
    public $socket;
    private $loop;

    public function __construct($socket, LoopInterface $loop)
    {
        $this->socket = $socket;
        $this->loop = $loop;
    }

    public function write($data)
    {
        $len = strlen($data);

        do {
            set_error_handler(function ($errno, $errstr, $errfile, $errline) {
                throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
                return false;
            });

            try {
                $sent = fwrite($this->socket, $data);
            } catch (\ErrorException $e) {
                $sent = false;
                $error = $e->getMessage();
            }

            restore_error_handler();

            if (false === $sent) {
                $error = $error ?: 'Unable to write to socket';
                $this->emit('error', array($error, $this));
                return;
            }
            $len -= $sent;
            $data = substr($data, $sent);
        } while ($len > 0);
    }

    public function end()
    {
        $this->emit('end');
        $this->loop->removeStream($this->socket);
        $this->removeAllListeners();
        fclose($this->socket);
    }

    public function handleData($socket)
    {
        $data = @stream_socket_recvfrom($socket, $this->bufferSize);
        if ('' === $data || false === $data) {
            $this->end();
        } else {
            $this->emit('data', array($data));
        }
    }
}
<commit_msg>[Socket] Connection self-emit<commit_after><?php

namespace React\Socket;

use Evenement\EventEmitter;
use React\EventLoop\LoopInterface;

class Connection extends EventEmitter implements ConnectionInterface
{
    public $bufferSize = 4096;
    public $socket;
    private $loop;

    public function __construct($socket, LoopInterface $loop)
    {
        $this->socket = $socket;
        $this->loop = $loop;
    }

    public function write($data)
    {
        $len = strlen($data);

        do {
            set_error_handler(function ($errno, $errstr, $errfile, $errline) {
                throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
                return false;
            });

            try {
                $sent = fwrite($this->socket, $data);
            } catch (\ErrorException $e) {
                $sent = false;
                $error = $e->getMessage();
            }

            restore_error_handler();

            if (false === $sent) {
                $error = $error ?: 'Unable to write to socket';
                $this->emit('error', array($error, $this));
                return;
            }
            $len -= $sent;
            $data = substr($data, $sent);
        } while ($len > 0);
    }

    public function end()
    {
        $this->emit('end', array($this));
        $this->loop->removeStream($this->socket);
        $this->removeAllListeners();
        fclose($this->socket);
    }

    public function handleData($socket)
    {
        $data = @stream_socket_recvfrom($socket, $this->bufferSize);
        if ('' === $data || false === $data) {
            $this->end();
        } else {
            $this->emit('data', array($data, $this));
        }
    }
}

{'fraction_non_alphanumeric': 0.14761765565624085, 'fraction_numerical': 0.0035077462730195848, 'mean_word_length': 1.7730956239870341, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4603131', 'n_tokens_mistral': 986, 'n_tokens_neox': 950, 'n_words': 212}