<commit_before><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'io.sys.Ftok',
    'io.IOException',
    'io.sys.IPCMessage'
  );
  
  define('IPC_QUEUE_PERM',  0666);
  define('IPC_MSG_MAXSIZE', 16384);
  
  /**
   * Send System V IPC messages
   * <quote>
   * Inter process messaging (IPC) is a great way to deal with communicating
   * threads. If you have forked processes, this could be a great way 
   * of passing out work to them.
   * </quote>
   *
   * Usage example [with threads]
   * <code>
   *   require('lang.base.php');
   *   xp::sapi('cli');
   *
   *   uses(
   *     'io.sys.IPCQueue',
   *     'io.sys.Ftok', 
   *     'lang.Thread'
   *
   *   );
   *
   *   class senderThread extends Thread {
   *     var
   *       $num  = 0;
   *
   *     function __construct($num) {
   *       $this->num= $num;
   *       $this->queue= &new IPCQueue(8925638);
   *       parent::__construct('sender.'.$this->num);
   *     }
   *
   *     function run() {
   *       while ($this->sent < $this->num) {
   *         Thread::sleep(1000);
   *         $this->queue->putMessage(new IPCMessage('hello world'));
   *         $this->sent++;     
   *
   *       }
   *       Console::writeLinef(
   *         "<%s> sent %d messages\n",
   *         $this->name, $this->num
   *       );
   *     }
   *   }
   *
   *   class receiverThread extends Thread {
   *
   *     function __construct($name) {
   *       $this->queue= &new IPCQueue(8925638);
   *       parent::__construct('receiver');
   *     }
   *
   *     function run() {
   *
   *       while (0 == $this->queue->getQuantity()) {
   *         Console::writeLinef('<%s> Sleeping...', $this->name);
   *         Thread::sleep(1000);
   *       }
   *
   *       while ($message= $this->queue->getMessage()) {
   *
   *         Console::writeLinef(
   *           "<%s> receiving message:\n -> %s\n",
   *           $this->name, $message->getMessage()
   *         );
   *         Thread::sleep(1000);
   *       }
   *       Console::writeLinef(
   *         'There are %d messages in queue',
   *         $this->queue->getQuantity()
   *       );
   *       $this->queue->removeQueue();
   *       Console::writeLine("All messages received, queue removed.");
   *
   *     }
   *   }
   *
   *   $t[0]= &new senderThread(2);
   *   $t[0]->start();
   *   $t[1]= &new receiverThread();
   *  $t[1]->start();
   *   var_dump($t[0]->join(), $t[1]->join());
   * </code>
   *
   * @purpose  Send and receive System V IPC messages
   */
  class IPCQueue extends Object {
    var
      $key      = 0,
      $id       = 0,
      $stat     = array();

    /**
     * Constructor
     *
     * @access  private
     * @param   int System V IPC keys default NULL
     */  
    function __construct($key= NULL) {
      $this->key= (NULL == $key) ? Ftok::get() : $key;
      $this->id= msg_get_queue($this->key, IPC_QUEUE_PERM);
      $this->stat= msg_stat_queue($this->id);
    }
    
    
    /**
     * Put a message into queue
     *
     * @access  public
     * @param   io.sys.IPCMessage
     * @param   bool serialize default TRUE<commit_msg>- QA: WS fixes<commit_after><?php
/* This class is part of the XP framework
 *
 * $Id$ 
 */

  uses(
    'io.sys.Ftok',
    'io.IOException',
    'io.sys.IPCMessage'
  );
  
  define('IPC_QUEUE_PERM',  0666);
  define('IPC_MSG_MAXSIZE', 16384);
  
  /**
   * Send System V IPC messages
   * <quote>
   * Inter process messaging (IPC) is a great way to deal with communicating
   * threads. If you have forked processes, this could be a great way 
   * of passing out work to them.
   * </quote>
   *
   * Usage example [with threads]
   * <code>
   *   require('lang.base.php');
   *   xp::sapi('cli');
   *
   *   uses(
   *     'io.sys.IPCQueue',
   *     'io.sys.Ftok', 
   *     'lang.Thread'
   *   );
   *
   *   class senderThread extends Thread {
   *     var
   *       $num  = 0;
   *
   *     function __construct($num) {
   *       $this->num= $num;
   *       $this->queue= &new IPCQueue(8925638);
   *       parent::__construct('sender.'.$this->num);
   *     }
   *
   *     function run() {
   *       while ($this->sent < $this->num) {
   *         Thread::sleep(1000);
   *         $this->queue->putMessage(new IPCMessage('hello world'));
   *         $this->sent++;     
   *
   *       }
   *       Console::writeLinef(
   *         "<%s> sent %d messages\n",
   *         $this->name, $this->num
   *       );
   *     }
   *   }
   *
   *   class receiverThread extends Thread {
   *
   *     function __construct($name) {
   *       $this->queue= &new IPCQueue(8925638);
   *       parent::__construct('receiver');
   *     }
   *
   *     function run() {
   *
   *       while (0 == $this->queue->getQuantity()) {
   *         Console::writeLinef('<%s> Sleeping...', $this->name);
   *         Thread::sleep(1000);
   *       }
   *
   *       while ($message= $this->queue->getMessage()) {
   *
   *         Console::writeLinef(
   *           "<%s> receiving message:\n -> %s\n",
   *           $this->name, $message->getMessage()
   *         );
   *         Thread::sleep(1000);
   *       }
   *       Console::writeLinef(
   *         'There are %d messages in queue',
   *         $this->queue->getQuantity()
   *       );
   *       $this->queue->removeQueue();
   *       Console::writeLine("All messages received, queue removed.");
   *
   *     }
   *   }
   *
   *   $t[0]= &new senderThread(2);
   *   $t[0]->start();
   *   $t[1]= &new receiverThread();
   *   $t[1]->start();
   *   var_dump($t[0]->join(), $t[1]->join());
   * </code>
   *
   * @purpose  Send and receive System V IPC messages
   */
  class IPCQueue extends Object {
    var
      $key      = 0,
      $id       = 0,
      $stat     = array();

    /**
     * Constructor
     *
     * @access  public
     * @param   int System V IPC keys default NULL
     */  
    function __construct($key= NULL) {
      $this->key= (NULL == $key) ? Ftok::get() : $key;
      $this->id= msg_get_queue($this->key, IPC_QUEUE_PERM);
      $this->stat= msg_stat_queue($this->id);
    }
    
    /**
     * Put a message into queue
     *
     * @access  public
     * @param   io.sys.IPCMessage
     * @param   bool serialize default TRUE
{'fraction_non_alphanumeric': 0.17217169299505344, 'fraction_numerical': 0.014680070209031434, 'mean_word_length': 1.7335368512865241, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2472306', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2169, 'n_words': 422}