Bugfixed SharedMemoryBlock, added tests
This commit is contained in:
parent
dcb059e4be
commit
612cfc2035
@ -29,7 +29,7 @@ class SharedMemoryBlock
|
||||
*/
|
||||
public function __construct(KeyInterface $key, string $flags, int $memsize, int $perm = 0666)
|
||||
{
|
||||
if (!($shm_resource = shmop_open($key->getKey(), $memsize, $perm))) {
|
||||
if (!($shm_resource = shmop_open($key->getKey(), $flags, $perm, $memsize))) {
|
||||
throw new \RuntimeException("Unable to attach shm resource {$key}");
|
||||
}
|
||||
|
||||
|
25
tests/Shm/SharedMemoryBlockTest.php
Normal file
25
tests/Shm/SharedMemoryBlockTest.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Ipc\Shm;
|
||||
|
||||
use NoccyLabs\Ipc\Key\FileKey;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SharedMemoryBlockTest extends \PhpUnit\Framework\TestCase
|
||||
{
|
||||
public function testWritingAndReading()
|
||||
{
|
||||
$key = new FileKey(__DIR__);
|
||||
$shm = new SharedMemoryBlock($key, SharedMemoryBlock::FLAG_CREATE, 64);
|
||||
|
||||
$this->assertEquals(11, $shm->write("Hello World", 0));
|
||||
$this->assertEquals("Hello World", $shm->read(11, 0));
|
||||
$this->assertEquals(3, $shm->write("foo", 2));
|
||||
$this->assertEquals("Hefoo World", $shm->read(11, 0));
|
||||
|
||||
$shm->destroy();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user