From a52a53bbe7ad884562d7fb39c87442a38e331dd2 Mon Sep 17 00:00:00 2001 From: paulr Date: Tue, 20 Sep 2011 04:02:38 +1000 Subject: [PATCH] comms stuff (ipc that is) --- bin/cbfwrd.php | 14 +++++++++++++ libcbfwr/comms.php | 42 +++++++++++++++++++++++++++++++++++++++ libcbfwr/config.php | 5 ++++ unittests/readconfigfromshm.php | 26 ++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 0 deletions(-) create mode 100644 unittests/readconfigfromshm.php diff --git a/bin/cbfwrd.php b/bin/cbfwrd.php index 6f49afe..b5a91b3 100644 --- a/bin/cbfwrd.php +++ b/bin/cbfwrd.php @@ -20,4 +20,18 @@ glcas_pluginLoader(); error_log("CBFWRD starting"); $config = new Config(); + +// now we got into daemon modes +$cont = true; + +// setup our sem/shm stuff + +// this stuff needs to go in comms +while($cont) { + $comms = new Comms; + + $comms->putConfig($config->getConfig()); + + $cont = false; +} ?> \ No newline at end of file diff --git a/libcbfwr/comms.php b/libcbfwr/comms.php index 808d1f8..b1195c9 100644 --- a/libcbfwr/comms.php +++ b/libcbfwr/comms.php @@ -7,4 +7,46 @@ $STORE_KEY = ftok(realpath(dirname(__FILE__)), "s"); global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; +class Comms { + function __construct() + { + global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; + $this->semres = sem_get($LOCKING_KEY, 0666); + $this->msgres = msg_get_queue($MESSAGE_KEY, 0666); + } + + function getConfig() + { + global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; + sem_acquire($this->semres); + $shm_space = shm_attach($STORE_KEY, 16*1024*1024); + $config = shm_get_var($shm_space, 0); + sem_release($this->semres); + + return $config; + } + + function putConfig($config) + { + global $MESSAGE_KEY, $LOCKING_KEY, $STORE_KEY; + sem_acquire($this->semres); + $shm_space = shm_attach($STORE_KEY, 16*1024*1024); + shm_put_var($shm_space, 0, $config); + sem_release($this->semres); + } + + function waitForMessage() + { + + } + + function sendMessage() + { + + } + + private $semres, $msgres; + +} + ?> \ No newline at end of file diff --git a/libcbfwr/config.php b/libcbfwr/config.php index d9a8eb2..94cf1b3 100644 --- a/libcbfwr/config.php +++ b/libcbfwr/config.php @@ -78,6 +78,11 @@ class Config { } } + function getConfig() + { + return $this->config; + } + function applyConfig() { global $AM_DAEMON; diff --git a/unittests/readconfigfromshm.php b/unittests/readconfigfromshm.php new file mode 100644 index 0000000..f05849b --- /dev/null +++ b/unittests/readconfigfromshm.php @@ -0,0 +1,26 @@ +getConfig(); + +print_r($conf); + +?> \ No newline at end of file -- 1.7.0.4