Esempio n. 1
0
 private function _processrequest()
 {
     if (($this->msgsock = @socket_accept($this->sock)) === false) {
         gio::log("socket_accept() failed: reason: " . socket_strerror(socket_last_error($this->sock)), E_USER_ERROR);
         break;
     }
     gio::log("\nSocket: CONNECTION RECEIVED", VERBOSE);
     $this->_welcome();
     do {
         if (false === ($buf = @socket_read($this->msgsock, config::$maximumTransmissionLength, PHP_NORMAL_READ))) {
             gio::log("socket_read() failed: reason: " . socket_strerror(socket_last_error($this->msgsock)), E_USER_WARNING);
             break;
         }
         if (!($buf = trim($buf))) {
             continue;
         }
         gio::log("NEW REQUEST RECEIVED", VERBOSE);
         if ($buf == 'quit') {
             gio::log("Socket: Connection terminated by client!", VERBOSE);
             break;
         }
         if ($buf == 'restart') {
             $this->restart = true;
             gio::log("Socket: Restarting the server !!!", VERBOSE);
             $buf = 'shutdown';
         }
         if ($buf == 'shutdown') {
             gio::output("Processing request to stop the server ...");
             self::_out("Shuting down...");
             self::_flush();
             $this->stop = true;
             break;
         }
         if (!$this->stop) {
             $sockreply = Gmsg::process($buf);
             $this->_out($sockreply);
             $this->_flush();
             gio::log("Socket: REPLY SENT\n", VERBOSE);
         } else {
             $this->_out("...Terminating Server Process...");
             break;
         }
     } while (true);
     socket_close($this->msgsock);
     unset($this->msgsock);
     gio::log("\nSocket: CONNECTION ENDED", VERBOSE);
 }