Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 222... Línea 222...
222
            }
222
            }
223
        }
223
        }
224
        return $event;
224
        return $event;
225
    }
225
    }
Línea -... Línea 226...
-
 
226
 
-
 
227
 
-
 
228
    /**
-
 
229
     * Checks if the socket is created. If PHP version is greater or equals to 8 then,
-
 
230
     * it will check if the var is instance of \Socket otherwise it will check if is
-
 
231
     * a resource.
-
 
232
     *
-
 
233
     * @return bool Returns true if the socket is created, false otherwise.
-
 
234
     */
-
 
235
    private function isSocketCreated(): bool
-
 
236
    {
-
 
237
        // Before version 8, sockets are resources
-
 
238
        // After version 8, sockets are instances of Socket
-
 
239
        if (PHP_MAJOR_VERSION >= 8) {
-
 
240
            $socketClass = '\Socket';
-
 
241
            return self::$socket instanceof $socketClass;
-
 
242
        } else {
-
 
243
            return is_resource(self::$socket);
-
 
244
        }
-
 
245
    }
226
 
246
 
227
    /**
247
    /**
228
     * Creates a UDP socket resource and stores it with the class, or retrieves
248
     * Creates a UDP socket resource and stores it with the class, or retrieves
229
     * it if already instantiated and connected. Handles error-checking and
249
     * it if already instantiated and connected. Handles error-checking and
230
     * re-connecting if necessary. If $forceNewConnection is set to true, a new
250
     * re-connecting if necessary. If $forceNewConnection is set to true, a new
Línea 233... Línea 253...
233
     * @param bool $forceNewConnection
253
     * @param bool $forceNewConnection
234
     * @return Resource
254
     * @return Resource
235
     */
255
     */
236
    private function prepareSocket($forceNewConnection = false)
256
    private function prepareSocket($forceNewConnection = false)
237
    {
257
    {
238
        if (!is_resource(self::$socket)
258
        if (!$this->isSocketCreated()
239
            || $forceNewConnection
259
            || $forceNewConnection
240
            || socket_last_error(self::$socket)
260
            || socket_last_error(self::$socket)
241
        ) {
261
        ) {
242
            self::$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
262
            self::$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
243
            socket_clear_error(self::$socket);
263
            socket_clear_error(self::$socket);
Línea 284... Línea 304...
284
                );
304
                );
285
            }
305
            }
286
        }
306
        }
287
        return $this->options;
307
        return $this->options;
288
    }
308
    }
289
}
-
 
290
309
}
-
 
310