public static function kill() { Octave_pool::killAll(); if (self::$child_process) { exit; } while (self::$child_pids) { // Waiting for all the children to die while (-1 != ($pid = pcntl_waitpid(-1, $status))) { self::manageDeadPID($pid); } if (self::$child_pids) { usleep(100); } } self::closeServerSockets(); Octave_logger::log("Service stopped"); exit; }
protected function respond($response) { while (true) { $partial = $response['partial']; // This is partial, because the errors always follow if (!$this->write($response['response'], true)) { return $this->controller->everything() && false; } if (!$partial) { if ($response['error']) { Octave_logger::log("[" . $this->remoteIP . "] " . $response['error'], LOG_WARNING); } return $this->write(self::error_start . $response['error'], $partial); } $response = array('response' => $this->controller->more(), 'error' => $this->controller->lastError, 'partial' => $this->controller->partialResult); } }
public static function manageConnections() { $still_waiting = array(); foreach (self::$pending_connections as $cSocket) { if ($kid =& self::getChild($cSocket)) { $pid = pcntl_fork(); if ($pid == -1) { Octave_logger::log("Failed forking!", LOG_ERR); exit; } elseif ($pid) { // Parent Octave_daemon::$child_pids[$pid] = true; $kid->pid = $pid; $kid->close(); } else { // Child Octave_daemon::childMode(); chdir(self::$home_directory); $kid->entertain(); $kid->killSocket(); exit; } } else { $still_waiting[] = $cSocket; } } self::$pending_connections = $still_waiting; }
public function accept_connection() { $cSocket = @socket_accept($this->socket); // We're running non-blocking, so this just means that // nobody's knocking if ($cSocket === false) { return NULL; } if ($cSocket < 0) { $this->setError($this->getSocketError("Failed accepting connection"), LOG_ERR); socket_close($cSocket); return false; } if (!@socket_getpeername($cSocket, $remote_IP)) { $this->setError($this->getSocketError("Failed retrieving the remote IP address"), LOG_WARNING); socket_close($cSocket); return false; } // IP filtering, if enabled if (!$this->allow_ip($remote_IP)) { Octave_logger::log("Connection attempt from " . $remote_IP); socket_close($cSocket); return NULL; } return $cSocket; }