Skip to content
This repository was archived by the owner on Apr 21, 2022. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: amal/AzaLibEvent
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Anizoptera/AzaLibEvent
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 4 commits
  • 10 files changed
  • 1 contributor

Commits on May 27, 2013

  1. Verified

    This commit was signed with the committer’s verified signature.
    thecsw Sandy
    Copy the full SHA
    0c272fb View commit details

Commits on May 28, 2013

  1. Verified

    This commit was signed with the committer’s verified signature.
    thecsw Sandy
    Copy the full SHA
    206a884 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    thecsw Sandy
    Copy the full SHA
    7b3e0e6 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    thecsw Sandy
    Copy the full SHA
    de193b1 View commit details
Showing with 1,262 additions and 49 deletions.
  1. +12 −2 .travis.yml
  2. +16 −1 CHANGELOG.md
  3. +129 −1 Event.php
  4. +236 −29 EventBase.php
  5. +1 −2 EventBasic.php
  6. +128 −2 EventBuffer.php
  7. +658 −0 Tests/LibEventTest.php
  8. +3 −0 composer.json
  9. +64 −5 examples/basic_api.php
  10. +15 −7 examples/buffered_api.php
14 changes: 12 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -10,6 +10,16 @@ matrix:
- php: 5.5

before_script:
- composer install
- sudo apt-get -qq install libevent-dev
- sh -c " if [ \"\$(php --re libevent | grep 'does not exist')\" != '' ]; then
wget http://pecl.php.net/get/libevent-0.1.0.tgz;
tar -xzf libevent-0.1.0.tgz;
cd libevent-0.1.0 && phpize && ./configure && make && sudo make install;
echo "extension=libevent.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`;
fi"
- php -i | grep "libevent version"
- php --re libevent | grep Extension
- composer self-update
- composer install --dev --prefer-source

script: phpunit --configuration phpunit.xml.dist --coverage-text
script: phpunit --configuration phpunit.xml.dist --group=unit
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
CHANGELOG
=========

## Version 1.1 (work in progress)
## Version 1.2 (work in progress)


## Version 1.1 (28.05.2013)
- **MINOR:** Small fixes and improvements (amal)
- **FEATURE:** Support for max single read/write size in `EventBuffer` - 4 new methods (amal)
- **FEATURE:** `Event::setPriority` (amal)

26.05.2013
- **MINOR:** More complex examples (amal)
- **IMPROVED:** Better support for fork in the newest libevent versions (amal)
- **FEATURE:** Full fork control with `EventBase::fork()` (amal)
- **FEATURE:** Event loops manager moved from `CliBase` and improved (amal)

25.05.2013
- **FEATURE:** Reentrant loop invocation protection (needed for the newest libevent versions) (amal)
- **IMPROVED:** Tests added (amal)

09.05.2013
- **FEATURE:** `EventBuffer` reinitialization on the fly (amal)
- **FEATURE:** `EventBuffer::readAll()` and `EventBuffer::readAllClean()` helper methods (amal)
130 changes: 129 additions & 1 deletion Event.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,55 @@
*/
class Event extends EventBasic
{
/**
* Default priority
*
* @see setPriority
*/
const DEF_PRIORITY = 10;


/**
* Last addition timeout
*
* @see add
*
* @var int
*/
protected $timeout;

/**
* Signal number
*
* @see setSignal
*
* @var int|null
*/
protected $signo;

/**
* Read callback
*
* @var callable|null
*/
protected $cb;

/**
* Whether the event will persist
*
* @var bool
*/
protected $persist = true;

/**
* Callbacks argument
*
* @var mixed
*/
protected $arg;



/**
* {@inheritdoc}
*
@@ -26,6 +75,16 @@ class Event extends EventBasic
public function __construct()
{
parent::__construct();
$this->init();
}

/**
* Helper initialization method
*
* @throws Exception
*/
protected function init()
{
if (!$this->resource = event_new()) {
throw new Exception(
"Can't create new event resource (event_new)"
@@ -34,6 +93,39 @@ public function __construct()
}


/**
* Prepares event for forking in parent
*/
public function beforeFork()
{
if ($this->signo) {
$base = $this->base;
$this->free();
$this->base = $base;
} else {
$this->del();
}
}

/**
* Prepares event after forking in parent
*/
public function afterFork()
{
if ($this->signo) {
$this->init();
$this->setSignal(
$this->signo,
$this->cb,
$this->persist,
$this->arg
);
$this->setBase($this->base);
}
$this->add($this->timeout);
}


/**
* Adds an event to the set of monitored events.
*
@@ -55,6 +147,7 @@ public function add($timeout = -1)
"Can't add event (event_add)"
);
}
$this->timeout = $timeout;
return $this;
}

@@ -105,6 +198,35 @@ public function setBase($event_base)
return parent::setBase($event_base);
}

/**
* Assign a priority to an event.
*
* @see event_priority_set
*
* @param int $value <p>
* Priority level. Cannot be less than zero and
* cannot exceed maximum priority level of the
* event base (see {@link event_base_priority_init}()).
* </p>
*
* @return $this
*
* @throws Exception
*/
public function setPriority($value = self::DEF_PRIORITY)
{
$this->checkResource();
if (function_exists('event_priority_set')
&& !event_priority_set($this->resource, $value)
) {
throw new Exception(
"Can't set event priority to {$value} (event_priority_set)"
);
}
return $this;
}


/**
* {@inheritdoc}
*
@@ -188,7 +310,7 @@ public function set($fd, $events, $callback, $arg = null)
* </p>
* @param callback $callback <p>
* Callback function to be called when the matching event occurs.
* <br><tt>function(null $fd, int $events(8:EV_SIGNAL),
* <br><tt>function(int $signo, int $events(8:EV_SIGNAL),
* array $arg(Event $event, mixed $arg, int $signo)){}</tt>
* </p>
* @param bool $persist <p>
@@ -222,6 +344,12 @@ public function setSignal($signo, $callback,
"Can't prepare event (event_set) for $name ($signo) signal"
);
}

$this->signo = $signo;
$this->cb = $callback;
$this->persist = $persist;
$this->arg = $arg;

return $this;
}

Loading