Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Socket fix for PHP 8 (fixes #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimbtech committed Dec 5, 2020
1 parent 824f214 commit 204aba0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 3 additions & 3 deletions core/AutocompleteSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function openSocket(){
}

public function __destruct(){
if( is_resource($this->socket)){
if( Utilities::isSocketType($this->socket)){
socket_close($this->socket);
}
if( file_exists($this->socketpath)){
Expand All @@ -68,7 +68,7 @@ private function closeOtherSocket(){

socket_write($s, $msg, strlen($msg));
}
if(is_resource($s)){
if(Utilities::isSocketType($s)){
socket_close($s);
}

Expand All @@ -81,7 +81,7 @@ private function closeOtherSocket(){
private function connectionHandler( $connection ){
$buffer = "";
do{
if( !is_resource($connection) ){
if( !Utilities::isSocketType($connection) ){
return;
}
$buffer = @socket_read($connection, 256, PHP_NORMAL_READ);
Expand Down
16 changes: 15 additions & 1 deletion core/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
class Utilities {

const VERSION = 'v1.0.13';
const VERSION = 'v1.0.14';

const DEFAULT_LINE_LENGTH = 125;

Expand Down Expand Up @@ -140,6 +140,20 @@ public static function isOnline(string $url) : bool {
return false;
}
}

/**
* Checks if given variable is a socket.
* @param mixed $s the var to check
* @return bool is socket?
*/
public static function isSocketType($s) : bool {
if( class_exists('Socket') && version_compare(PHP_VERSION, '8.0.0', '>=') ){
return $s instanceof Socket;
}
else{
return is_resource($s);
}
}
}

?>
4 changes: 3 additions & 1 deletion core/platform/socketTester.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

require_once(__DIR__ . '/../Utilities.php');

function getSocketPath(){
return '/private/tmp/TaskTimeTerminateAutocomplete.sock';
//return getenv('USERPROFILE') . '/AppData/Local/Temp/TaskTimeTerminateAutocomplete.sock';
Expand All @@ -18,7 +20,7 @@ function getCompletion($prefix){
}
}
}
if(is_resource($s)){
if(Utilities::isSocketType($s)){
socket_close($s);
}
}
Expand Down

0 comments on commit 204aba0

Please sign in to comment.