<commit_before><?php

//The beginning of the TCP server class.
class tcp_server
{

//Some variable assignments.
public $bindaddr='[::]';
public $port=6000;
public $connect_func = false;
public $disconnect_func = false;
public $recv_func = false;
public $recv_length = 8192;
public $time_interval_func = false;
public $time_interval = 1;
public $time_protocol_check = 0.2;

private $sockets = Array();
private $socket_data = Array();
private $server_socket = false;
private $stream_select_timeout_sec = 0;
private $stream_select_timeout_msec = 200000;

public function __construct($bindaddr = false, $port = 0, $connect_func = false, $disconnect_func = false, $recv_func = false, $recv_length = 0, $time_interval_func = false, $time_interval = 1)
{
if ($bindaddr)
$this->bindaddr = $bindaddr;
if ($port)
$this->port = $port;
if ($connect_func)
$this->connect_func = $connect_func;
if ($disconnect_func)
$this->disconnect_func = $disconnect_func;
if ($recv_func)
$this->recv_func = $recv_func;
if ($recv_length)
$this->recv_length = $recv_length;
if ($time_interval_func)
$this->time_interval_func = $time_interval_func;
if ($time_interval)
$this->time_interval = $time_interval;
}

public function start()
{
$this->server_socket = @stream_socket_server("tcp://$this->bindaddr:$this->port", $errno, $errstr);
if ($this->server_socket === false)
//Socket creation and binding to the address failed.
return false;
stream_set_timeout($this->server_socket, $this->stream_select_timeout_sec, $this->stream_select_timeout_msec);
stream_set_blocking($this->server_socket, 0);
return true;
}

public function sockets()
{
return $this->sockets;
}

public function do_events()
{
//Accept a socket.
$this->accept();
//Let's do some data receiving and timer checking.
$this->recv_all_with_time_check();
}

public function accept()
{
$socket = @stream_socket_accept($this->server_socket, 0);
if ($socket === false)
return false;

$time_connected = microtime(true);
stream_set_blocking($socket, 0);
stream_set_timeout($socket, $this->stream_select_timeout_sec, $this->stream_select_timeout_msec);
$this->sockets_set($socket);
$this->socket_data_set($socket, "time_connected", $time_connected);
$this->socket_data_set($socket, "time_message_received", $time_connected);
return true;
}

public function send_all($data, $socket = false)
{
foreach ($this->sockets as $s_socket)
{
if ($socket !== false && $s_socket === $socket)
continue;
$this->send($s_socket, $data);
}
}

//Send raw data without processing.
public function send_raw($socket, $data)
{
if ($data === false)
return false;
$result = @stream_socket_sendto($socket, $data);
if ($result === -1)
{
//Writing probably failed.
$this->disconnect($socket);
return false;
}
else
{
$this->socket_data_set($socket, "time_message_sent", microtime(true));
return true;<commit_msg>Allows for raw sending of an empty string without setting the sent message time.<commit_after><?php

//The beginning of the TCP server class.
class tcp_server
{

//Some variable assignments.
public $bindaddr='[::]';
public $port=6000;
public $connect_func = false;
public $disconnect_func = false;
public $recv_func = false;
public $recv_length = 8192;
public $time_interval_func = false;
public $time_interval = 1;
public $time_protocol_check = 0.2;

private $sockets = Array();
private $socket_data = Array();
private $server_socket = false;
private $stream_select_timeout_sec = 0;
private $stream_select_timeout_msec = 200000;

public function __construct($bindaddr = false, $port = 0, $connect_func = false, $disconnect_func = false, $recv_func = false, $recv_length = 0, $time_interval_func = false, $time_interval = 1)
{
if ($bindaddr)
$this->bindaddr = $bindaddr;
if ($port)
$this->port = $port;
if ($connect_func)
$this->connect_func = $connect_func;
if ($disconnect_func)
$this->disconnect_func = $disconnect_func;
if ($recv_func)
$this->recv_func = $recv_func;
if ($recv_length)
$this->recv_length = $recv_length;
if ($time_interval_func)
$this->time_interval_func = $time_interval_func;
if ($time_interval)
$this->time_interval = $time_interval;
}

public function start()
{
$this->server_socket = @stream_socket_server("tcp://$this->bindaddr:$this->port", $errno, $errstr);
if ($this->server_socket === false)
//Socket creation and binding to the address failed.
return false;
stream_set_timeout($this->server_socket, $this->stream_select_timeout_sec, $this->stream_select_timeout_msec);
stream_set_blocking($this->server_socket, 0);
return true;
}

public function sockets()
{
return $this->sockets;
}

public function do_events()
{
//Accept a socket.
$this->accept();
//Let's do some data receiving and timer checking.
$this->recv_all_with_time_check();
}

public function accept()
{
$socket = @stream_socket_accept($this->server_socket, 0);
if ($socket === false)
return false;

$time_connected = microtime(true);
stream_set_blocking($socket, 0);
stream_set_timeout($socket, $this->stream_select_timeout_sec, $this->stream_select_timeout_msec);
$this->sockets_set($socket);
$this->socket_data_set($socket, "time_connected", $time_connected);
$this->socket_data_set($socket, "time_message_received", $time_connected);
return true;
}

public function send_all($data, $socket = false)
{
foreach ($this->sockets as $s_socket)
{
if ($socket !== false && $s_socket === $socket)
continue;
$this->send($s_socket, $data);
}
}

//Send raw data without processing.
public function send_raw($socket, $data)
{
if ($data === false)
return false;
$result = @stream_socket_sendto($socket, $data);
if ($result === -1)
{
//Writing probably failed.
$this->disconnect($socket);
return false;
}
else
{
if ($result)
$this->socket_data_set($socket, "time_message_sent", microtime(true));
return true;
{'fraction_non_alphanumeric': 0.15182328190743338, 'fraction_numerical': 0.00876577840112202, 'mean_word_length': 6.95676429567643, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '6572286', 'n_tokens_mistral': 1940, 'n_tokens_neox': 1886, 'n_words': 468}