This repository was archived by the owner on Mar 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ private function openSocket(){
5353 }
5454
5555 public function __destruct (){
56- if ( is_resource ($ this ->socket )){
56+ if ( Utilities:: isSocketType ($ this ->socket )){
5757 socket_close ($ this ->socket );
5858 }
5959 if ( file_exists ($ this ->socketpath )){
@@ -68,7 +68,7 @@ private function closeOtherSocket(){
6868
6969 socket_write ($ s , $ msg , strlen ($ msg ));
7070 }
71- if (is_resource ($ s )){
71+ if (Utilities:: isSocketType ($ s )){
7272 socket_close ($ s );
7373 }
7474
@@ -81,7 +81,7 @@ private function closeOtherSocket(){
8181 private function connectionHandler ( $ connection ){
8282 $ buffer = "" ;
8383 do {
84- if ( !is_resource ($ connection ) ){
84+ if ( !Utilities:: isSocketType ($ connection ) ){
8585 return ;
8686 }
8787 $ buffer = @socket_read ($ connection , 256 , PHP_NORMAL_READ );
Original file line number Diff line number Diff line change 44 */
55class Utilities {
66
7- const VERSION = 'v1.0.13 ' ;
7+ const VERSION = 'v1.0.14 ' ;
88
99 const DEFAULT_LINE_LENGTH = 125 ;
1010
@@ -140,6 +140,20 @@ public static function isOnline(string $url) : bool {
140140 return false ;
141141 }
142142 }
143+
144+ /**
145+ * Checks if given variable is a socket.
146+ * @param mixed $s the var to check
147+ * @return bool is socket?
148+ */
149+ public static function isSocketType ($ s ) : bool {
150+ if ( class_exists ('Socket ' ) && version_compare (PHP_VERSION , '8.0.0 ' , '>= ' ) ){
151+ return $ s instanceof Socket;
152+ }
153+ else {
154+ return is_resource ($ s );
155+ }
156+ }
143157}
144158
145159?>
Original file line number Diff line number Diff line change 11<?php
22
3+ require_once (__DIR__ . '/../Utilities.php ' );
4+
35function getSocketPath (){
46 return '/private/tmp/TaskTimeTerminateAutocomplete.sock ' ;
57 //return getenv('USERPROFILE') . '/AppData/Local/Temp/TaskTimeTerminateAutocomplete.sock';
@@ -18,7 +20,7 @@ function getCompletion($prefix){
1820 }
1921 }
2022 }
21- if (is_resource ($ s )){
23+ if (Utilities:: isSocketType ($ s )){
2224 socket_close ($ s );
2325 }
2426 }
You can’t perform that action at this time.
0 commit comments