Change addressing system for message queue of phones to fix issue #189 on 32 bits systems

This commit is contained in:
osaajani 2022-09-28 20:01:55 +02:00
parent ea744d31e2
commit 3dd5e099e8
4 changed files with 25 additions and 25 deletions

View File

@ -1 +1 @@
v3.5.2
v3.5.3

View File

@ -23,7 +23,6 @@ class Phone extends AbstractDaemon
private $read_delay = 20 / 0.5;
private $read_tick = 0;
private $msg_queue;
private $msg_queue_id;
private $webhook_queue;
private $last_message_at;
private $phone;
@ -38,7 +37,6 @@ class Phone extends AbstractDaemon
public function __construct(array $phone)
{
$this->phone = $phone;
$this->msg_queue_id = (int) (QUEUE_ID_PHONE_PREFIX . $this->phone['id']);
$name = 'RaspiSMS Daemon Phone ' . $this->phone['id'];
$logger = new Logger($name);
@ -87,7 +85,7 @@ class Phone extends AbstractDaemon
//Set last message at to construct time
$this->last_message_at = microtime(true);
$this->msg_queue = msg_get_queue($this->msg_queue_id);
$this->msg_queue = msg_get_queue(QUEUE_ID_PHONE);
//Instanciate adapter
$adapter_class = $this->phone['adapter'];
@ -98,11 +96,7 @@ class Phone extends AbstractDaemon
public function on_stop()
{
//Delete queue on daemon close
$this->logger->info('Closing queue : ' . $this->msg_queue_id);
msg_remove_queue($this->msg_queue);
$this->logger->info('Stopping Phone daemon with pid ' . getmypid());
$this->logger->info('Stopping Phone daemon with pid ' . getmypid());
}
public function handle_other_signals($signal)
@ -125,8 +119,10 @@ class Phone extends AbstractDaemon
$maxsize = 409600;
$message = null;
// Message type is forged from a prefix concat with the phone ID
$message_type = (int) QUEUE_TYPE_SEND_MSG_PREFIX . $this->phone['id'];
$error_code = null;
$success = msg_receive($this->msg_queue, QUEUE_TYPE_SEND_MSG, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT, $error_code); //MSG_IPC_NOWAIT == dont wait if no message found
$success = msg_receive($this->msg_queue, $message_type, $msgtype, $maxsize, $message, true, MSG_IPC_NOWAIT, $error_code); //MSG_IPC_NOWAIT == dont wait if no message found
if (!$success && MSG_ENOMSG !== $error_code)
{

View File

@ -23,7 +23,7 @@ class Sender extends AbstractDaemon
private $internal_scheduled;
private $internal_received;
private $bdd;
private $queues = [];
private $msg_queue;
public function __construct()
{
@ -62,15 +62,14 @@ class Sender extends AbstractDaemon
{
foreach ($smss_per_scheduled as $id_scheduled => $smss)
{
//If queue not already exists
if (!msg_queue_exists($QUEUE_ID_PHONE) || !isset($this->queue))
{
$this->msg_queue = msg_get_queue(QUEUE_ID_PHONE);
}
foreach ($smss as $sms)
{
//If queue not already exists
$queue_id = (int) (QUEUE_ID_PHONE_PREFIX . $sms['id_phone']);
if (!msg_queue_exists($queue_id) || !isset($queues[$queue_id]))
{
$this->queues[$queue_id] = msg_get_queue($queue_id);
}
$msg = [
'id_user' => $sms['id_user'],
'id_scheduled' => $sms['id_scheduled'],
@ -82,8 +81,10 @@ class Sender extends AbstractDaemon
'medias' => $sms['medias'] ?? [],
];
msg_send($this->queues[$queue_id], QUEUE_TYPE_SEND_MSG, $msg);
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . $queue_id . '.');
// Message type is forged from a prefix concat with the phone ID
$message_type = (int) QUEUE_TYPE_SEND_MSG_PREFIX . $sms['id_phone'];
msg_send($this->msg_queue, $message_type, $msg);
$this->logger->info('Transmit sms send signal to phone ' . $sms['id_phone'] . ' on queue ' . QUEUE_ID_PHONE . ' with message type ' . $message_type . '.');
}
$this->logger->info('Scheduled ' . $id_scheduled . ' treated and deleted.');
@ -99,6 +100,10 @@ class Sender extends AbstractDaemon
public function on_stop()
{
//Delete queue on daemon close
$this->logger->info('Closing queue : ' . $this->msg_queue);
msg_remove_queue($this->msg_queue);
$this->logger->info('Stopping Sender with pid ' . getmypid());
}

View File

@ -53,17 +53,16 @@
],
//Phone messages types
'QUEUE_ID_PHONE_PREFIX' => ftok(__FILE__, 'p'),
'QUEUE_TYPE_SEND_MSG' => 1,
'QUEUE_TYPE_RECEIVE_MSG' => 2,
'QUEUE_ID_PHONE' => ftok(__FILE__, 'p'),
'QUEUE_TYPE_SEND_MSG_PREFIX' => 100,
//Queues ids
'QUEUE_ID_WEBHOOK' => ftok(__FILE__, 'w'),
'QUEUE_TYPE_WEBHOOK' => 3,
'QUEUE_TYPE_WEBHOOK' => 100,
//Queue email
'QUEUE_ID_EMAIL' => ftok(__FILE__, 'e'),
'QUEUE_TYPE_EMAIL' => 3,
'QUEUE_TYPE_EMAIL' => 100,
//User default settings
'USER_DEFAULT_SETTINGS' => [