<commit_before><?php
	/*****************************************************************************

	The MIT License (MIT)

	Copyright (c) 2013 <NAME> <<EMAIL>>

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the 'Software'), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.

	*****************************************************************************/

	if (!class_exists( 'OObject' )) { die(); }

	class oSocketFrame {

		public $FIN = FALSE;
		public $opcode;
		public $mask;
		public $len;
		public $msg = "";

	}

	class oClient {
		
	}

	/********************************************************************************************************************

		oWebSocket:

			1.  Establish a connection on specified host and port
			2.	Check for new connections: Basically we're checking to see if our original socket has been added to the
				changed array and if so we now it has a new connection waiting to be handled.

				//	1.	accpet new socket
				//	2.	add socket to socket list
				//	3.	read data sent by the socket
				//	4.	perform websocket handshake
				//	5.	store the client data
				//	6.	remove new socket from changed array

			3.	Loop through all the changed sockets

				//	1.	read from changed sockets
				//	2.	if EOF then close connection.

	********************************************************************************************************************/

	Class oWebSocket extends ODBO {

		public function __construct($params){

			/*************************************************************************************************
				
				1.  Establish a connection on specified host and port

			*************************************************************************************************/

			$this->host = !empty($params["host"])?$params["host"]:"localhost";
			$this->port = !empty($params["port"])?$params["port"]:"80";

			$this->console("Binding to ".$this->host.":".$this->port."\n");

			$listenstr = 	"tls://".$this->host.":".$this->port;
			//$context = 		stream_context_create();
			$context = 		stream_context_create( array( "ssl" => array( "local_cert"=>__WEB_SOCKET_CERT__, "local_pk"=>__WEB_SOCKET_KEY__, "passphrase" => __<PASSWORD> ) ) );
			$this->socket = stream_socket_server($listenstr,$errno,$errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN,$context);

			//$this->console("Enabling crypto...");
			//stream_socket_enable_crypto($this->socket,TRUE,STREAM_CRYPTO_METHOD_SSLv3_SERVER);
			//$this->console("done\n");

			//$conn = stream_socket_accept($s);
			// do stuff with your new connection here 

			/********
			//Create TCP/IP sream socket
			$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			//reuseable port
			socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
			//bind socket to specified host
			socket_bind($this->socket, $this->host, $this->port);
			//listen to port
			socket_listen($this->socket);
			$this->console("Listening on ".$this->host.":".$this->port."\n");
			****/

			$this->sockets = array( $this->socket );
			$this->cData = array();

			while(true){

				$changed = $this->sockets;

				stream_select( $changed, $null, $null, 0, 10 );
				//socket_select( $changed, $null, $null, 0, 10 );

				/*************************************************************************************************

					2.	Check for new connections: Basically we're checking to see if our original socket has 
						been added to the changed array and if so we now it has a new connection waiting to be 
						handled.

						//	1.	accpet new socket
						//	2.	add socket to socket list
						//	3.	read data sent by the socket
						//	4.	perform websocket handshake
						//	5.	store the client data
						//	6.	remove new socket from changed array

				*************************************************************************************************/

				if( in_array($this->socket,$changed) ){
					
					$this->console("Attempting to connect a new client.\n");
					$new_socket = stream_socket_accept($this->socket);						//	1.	accpet new socket
					$this->sockets[] = $new_socket; 										//	2.	add socket to socket list
					$request = stream_socket_recvfrom($new_socket, 1024);					//	3.	read data sent by the socket

					$this->console("Performing websocket handshake.\n");
					$ouser = $this->handshake($request, $new_socket); 						//	4.	perform websocket handshake
					$this->cData[ array_search($new_socket,$this->sockets) ] = $ouser;		//	5.	store the client data

					$this->console($ouser->ouser_first_name." ".$ouser->ouser_last_name." has logged on.\n");

					$response = (object)array( 'channel'=>'all', 'type'=>'broadcast', 'message'=>$ouser->ouser_first_name.' '.$ouser->ouser_last_name.' connected.' ); //prepare json data
					$this->send($response); //notify all users about new connection

					$found_socket = array_search($this->socket, $changed);
					unset($changed[$found_socket]);											//	6.	remove new socket from changed array

					$this->console( (count($this->sockets)-1)." users connected.\n" );
					
				}

				/*************************************************************************************************

					3.	Loop through all the changed sockets

						//	1.	read from changed sockets
						//	2.	if EOF then close connection.

				*************************************************************************************************/
				
				
				if( !empty($changed) ){
					$this->console("%s","\n***********************************************\n","WhiteBold");
					$this->console("%s","\tMessage Received: ".count($changed)."\n","WhiteBold");
					$this->console("%s","***********************************************\n","WhiteBold");
					sleep(10);
				}<commit_msg>tls test<commit_after><?php
	/*****************************************************************************

	The MIT License (MIT)

	Copyright (c) 2013 <NAME> <<EMAIL>>

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the 'Software'), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.

	*****************************************************************************/

	if (!class_exists( 'OObject' )) { die(); }

	class oSocketFrame {

		public $FIN = FALSE;
		public $opcode;
		public $mask;
		public $len;
		public $msg = "";

	}

	class oClient {
		
	}

	/********************************************************************************************************************

		oWebSocket:

			1.  Establish a connection on specified host and port
			2.	Check for new connections: Basically we're checking to see if our original socket has been added to the
				changed array and if so we now it has a new connection waiting to be handled.

				//	1.	accpet new socket
				//	2.	add socket to socket list
				//	3.	read data sent by the socket
				//	4.	perform websocket handshake
				//	5.	store the client data
				//	6.	remove new socket from changed array

			3.	Loop through all the changed sockets

				//	1.	read from changed sockets
				//	2.	if EOF then close connection.

	********************************************************************************************************************/

	Class oWebSocket extends ODBO {

		public function __construct($params){

			/*************************************************************************************************
				
				1.  Establish a connection on specified host and port

			*************************************************************************************************/

			$this->host = !empty($params["host"])?$params["host"]:"localhost";
			$this->port = !empty($params["port"])?$params["port"]:"80";

			$this->console("Binding to ".$this->host.":".$this->port."\n");

			$listenstr = 	"tls://".$this->host.":".$this->port;
			//$context = 		stream_context_create();
			$context = 		stream_context_create( array( "ssl" => array( "local_cert"=>__WEB_SOCKET_CERT__, "local_pk"=>__WEB_SOCKET_KEY__, "passphrase" => __WEB_SOCKET_KEY_PASS__ ) ) );
			$this->socket = stream_socket_server($listenstr,$errno,$errstr,STREAM_SERVER_BIND|STREAM_SERVER_LISTEN,$context);

			//$this->console("Enabling crypto...");
			//stream_socket_enable_crypto($this->socket,TRUE,STREAM_CRYPTO_METHOD_SSLv3_SERVER);
			//$this->console("done\n");

			//$conn = stream_socket_accept($s);
			// do stuff with your new connection here 

			/********
			//Create TCP/IP sream socket
			$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
			//reuseable port
			socket_set_option($this->socket, SOL_SOCKET, SO_REUSEADDR, 1);
			//bind socket to specified host
			socket_bind($this->socket, $this->host, $this->port);
			//listen to port
			socket_listen($this->socket);
			$this->console("Listening on ".$this->host.":".$this->port."\n");
			****/

			$this->sockets = array( $this->socket );
			$this->cData = array();

			while(true){

				$changed = $this->sockets;

				stream_select( $changed, $null, $null, 0, 10 );
				//socket_select( $changed, $null, $null, 0, 10 );

				/*************************************************************************************************

					2.	Check for new connections: Basically we're checking to see if our original socket has 
						been added to the changed array and if so we now it has a new connection waiting to be 
						handled.

						//	1.	accpet new socket
						//	2.	add socket to socket list
						//	3.	read data sent by the socket
						//	4.	perform websocket handshake
						//	5.	store the client data
						//	6.	remove new socket from changed array

				*************************************************************************************************/

				if( in_array($this->socket,$changed) ){
					
					$this->console("Attempting to connect a new client.\n");
					$new_socket = stream_socket_accept($this->socket);						//	1.	accpet new socket
					$this->sockets[] = $new_socket; 										//	2.	add socket to socket list
					$request = stream_socket_recvfrom($new_socket, 1024);					//	3.	read data sent by the socket

					$this->console("Performing websocket handshake.\n");
					$ouser = $this->handshake($request, $new_socket); 						//	4.	perform websocket handshake
					$this->cData[ array_search($new_socket,$this->sockets) ] = $ouser;		//	5.	store the client data

					$this->console($ouser->ouser_first_name." ".$ouser->ouser_last_name." has logged on.\n");

					$response = (object)array( 'channel'=>'all', 'type'=>'broadcast', 'message'=>$ouser->ouser_first_name.' '.$ouser->ouser_last_name.' connected.' ); //prepare json data
					$this->send($response); //notify all users about new connection

					$found_socket = array_search($this->socket, $changed);
					unset($changed[$found_socket]);											//	6.	remove new socket from changed array

					$this->console( (count($this->sockets)-1)." users connected.\n" );
					
				}

				/*************************************************************************************************

					3.	Loop through all the changed sockets

						//	1.	read from changed sockets
						//	2.	if EOF then close connection.

				*************************************************************************************************/
				
				
				if( !empty($changed) ){
					$this->console("%s","\n***********************************************\n","WhiteBold");
					$this->console("%s","\tMessage Received: ".count($changed)."\n","WhiteBold");
					$this->console("%s","***********************************************\n","WhiteBold");
					exit();
				}
{'fraction_non_alphanumeric': 0.27116610423697035, 'fraction_numerical': 0.007199100112485939, 'mean_word_length': 3.9465875370919883, 'pattern_counts': {'":': 6, '<': 12, '<?xml version=': 0, '>': 112, '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': '3581150', 'n_tokens_mistral': 4377, 'n_tokens_neox': 3514, 'n_words': 1137}