forked from kriswallsmith/spork
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Changed - #5: Preserve and restore previous signal handler. Refactored event dispatcher. ### Removed - #5: Removed the method `addListener` from the `ProcessManager` class. Add signal/normal listeners through the event dispatcher on the process manager. ### Fixed - #7: Fixed missing null terminator handling on shared memory blocks. - #8: Fixed parent's shutdown function being executed in child processes.
- Loading branch information
Showing
25 changed files
with
1,590 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/.php_cs | ||
/.phpunit.result.cache | ||
/composer.lock | ||
/coverage | ||
/phpstan.neon | ||
/phpunit.xml | ||
/vendor |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
parameters: | ||
level: max | ||
level: 5 | ||
paths: | ||
- src | ||
- tests | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the thelevti/spork package. | ||
* | ||
* (c) Petr Levtonov <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spork\EventDispatcher; | ||
|
||
use Symfony\Contracts\EventDispatcher\Event as BaseEvent; | ||
|
||
/** | ||
* Holds the signal information. | ||
*/ | ||
class SignalEvent extends BaseEvent | ||
{ | ||
/** | ||
* Event prefix used to construct the full event name, which contains the | ||
* signal number. | ||
* | ||
* @var string PREFIX | ||
*/ | ||
private const PREFIX = 'spork.signal.'; | ||
|
||
/** | ||
* The signal being handled. | ||
* | ||
* @var int $signo | ||
*/ | ||
private $signo; | ||
|
||
/** | ||
* If operating systems supports siginfo_t structures, this will be an array | ||
* of signal information dependent on the signal. | ||
* | ||
* @var mixed | ||
*/ | ||
private $signinfo; | ||
|
||
/** | ||
* Gets the event name for a signal number. | ||
* | ||
* @param int $signo A signal number. | ||
* @return string The event name for a signal number. | ||
*/ | ||
public static function getEventName(int $signo): string | ||
{ | ||
return self::PREFIX . $signo; | ||
} | ||
|
||
/** | ||
* Constructs a new instance of the Event class. | ||
* | ||
* @param int $signo The signal being handled. | ||
* @param mixed $signinfo If operating systems supports siginfo_t | ||
* structures, this will be an array of signal | ||
* information dependent on the signal. | ||
*/ | ||
public function __construct(int $signo, $signinfo) | ||
{ | ||
$this->signo = $signo; | ||
$this->signinfo = $signinfo; | ||
} | ||
|
||
/** | ||
* Gets the signal being handled. | ||
* | ||
* @return int The signal being handled. | ||
*/ | ||
public function getSigno(): int | ||
{ | ||
return $this->signo; | ||
} | ||
|
||
/** | ||
* If operating systems supports siginfo_t structures, this will get the | ||
* array of signal information dependent on the signal. | ||
* | ||
* @return mixed If operating systems supports siginfo_t structures, this | ||
* will be an array of signal information dependent on the | ||
* signal. | ||
*/ | ||
public function getSigninfo() | ||
{ | ||
return $this->signinfo; | ||
} | ||
|
||
/** | ||
* Gets the event name of the signal being handled. | ||
* | ||
* @return string The event name of the signal being handled. | ||
*/ | ||
public function getName(): string | ||
{ | ||
return static::getEventName($this->getSigno()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the thelevti/spork package. | ||
* | ||
* (c) Petr Levtonov <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spork\EventDispatcher; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
|
||
/** | ||
* Extends the core event dispatcher with signal handling capabilities. Add and | ||
* remove signal listeners or dispatch a signal directly. | ||
*/ | ||
class SignalEventDispatcher extends EventDispatcher implements | ||
SignalEventDispatcherInterface | ||
{ | ||
use SignalEventDispatcherTrait; | ||
} |
59 changes: 59 additions & 0 deletions
59
src/Spork/EventDispatcher/SignalEventDispatcherInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the thelevti/spork package. | ||
* | ||
* (c) Petr Levtonov <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spork\EventDispatcher; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* Extends the core event dispatcher interface with signal handling | ||
* capabilities. Add and remove signal listeners or dispatch a signal directly. | ||
*/ | ||
interface SignalEventDispatcherInterface extends EventDispatcherInterface | ||
{ | ||
/** | ||
* Signal handler that dispatches events. | ||
* | ||
* @param int $signo The signal being handled. | ||
* @param mixed $signinfo If operating systems supports siginfo_t | ||
* structures, this will be an array of signal | ||
* information dependent on the signal. | ||
* @return \Spork\EventDispatcher\SignalEvent Holds the signal information. | ||
*/ | ||
public function dispatchSignal(int $signo, $signinfo): SignalEvent; | ||
|
||
/** | ||
* Adds a signal listener that listens on the specified signal. | ||
* | ||
* @param int $signo The signal number. | ||
* @param callable $listener The listener. | ||
* @param int $priority The higher this value, the earlier an event | ||
* listener will be triggered in the chain | ||
* (defaults to 0) | ||
* @return void | ||
*/ | ||
public function addSignalListener( | ||
int $signo, | ||
callable $listener, | ||
int $priority = 0 | ||
): void; | ||
|
||
/** | ||
* Removes a signal listener from the specified signal. | ||
* | ||
* @param int $signo The signal to remove a listener from. | ||
* @param callable $listener The listener to remove. | ||
* @return void | ||
*/ | ||
public function removeSignalListener(int $signo, callable $listener): void; | ||
} |
Oops, something went wrong.