[Phpfwconfsys-submits] Daemon-Alpha Daemon.Class.php,1.2,1.3 DaemonSession.Class.php,1.1,1.2 Server.
Status: Planning
Brought to you by:
piotrbanasik
From: <pio...@us...> - 2003-01-08 04:39:55
|
Update of /cvsroot/phpfwconfsys/Daemon-Alpha In directory sc8-pr-cvs1:/tmp/cvs-serv10131 Modified Files: Daemon.Class.php DaemonSession.Class.php Server.Class.php Socket.Class.php Utility.php Log Message: added vim fold markers to the code Index: Daemon.Class.php =================================================================== RCS file: /cvsroot/phpfwconfsys/Daemon-Alpha/Daemon.Class.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Daemon.Class.php 8 Jan 2003 02:50:54 -0000 1.2 --- Daemon.Class.php 8 Jan 2003 04:39:51 -0000 1.3 *************** *** 17,21 **** var $Session; ! function Daemon($settings) { $this->DaemonSettings = $settings; --- 17,21 ---- var $Session; ! function Daemon($settings) // {{{ { $this->DaemonSettings = $settings; *************** *** 45,51 **** return; } ! } ! function Start() { dprint("Daemon::Start()"); --- 45,51 ---- return; } ! } //}}} ! function Start() // {{{ { dprint("Daemon::Start()"); *************** *** 54,66 **** $this->Server = new Server($this->Socket, &$a, $PreforkCount); $this->Server->Start(); ! } ! function Hook_SIGUSR1() { dprint("Daemon::Hook_SIGUSR1()"); $this->Active = false; ! } ! function HandleConnection($Sock) { dprint("Daemon::HandleConnection(&$Sock)"); --- 54,66 ---- $this->Server = new Server($this->Socket, &$a, $PreforkCount); $this->Server->Start(); ! } // }}} ! function Hook_SIGUSR1() // {{{ { dprint("Daemon::Hook_SIGUSR1()"); $this->Active = false; ! } // }}} ! function HandleConnection($Sock) // {{{ { dprint("Daemon::HandleConnection(&$Sock)"); *************** *** 107,116 **** $this->Session->Close(); return true; ! } ! function Shutdown() { $this->Socket->Close(); ! } } --- 107,116 ---- $this->Session->Close(); return true; ! } // }}} ! function Shutdown() // {{{ { $this->Socket->Close(); ! } // }}} } Index: DaemonSession.Class.php =================================================================== RCS file: /cvsroot/phpfwconfsys/Daemon-Alpha/DaemonSession.Class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DaemonSession.Class.php 8 Jan 2003 02:50:54 -0000 1.1 --- DaemonSession.Class.php 8 Jan 2003 04:39:51 -0000 1.2 *************** *** 23,27 **** var $CharData = ""; ! function DaemonSession(&$daemon, &$sock) { $this->Socket =& $sock; --- 23,27 ---- var $CharData = ""; ! function DaemonSession(&$daemon, &$sock) //{{{ { $this->Socket =& $sock; *************** *** 35,47 **** $this->State = "none"; ! } ! function SocketWrite($msg) { $r = $this->Socket->Write($msg); if ($r === false) $this->Error = true; ! } ! function SocketError($msg) { dprint("DaemonSession::SocketError($msg)"); --- 35,47 ---- $this->State = "none"; ! } // }}} ! function SocketWrite($msg) // {{{ { $r = $this->Socket->Write($msg); if ($r === false) $this->Error = true; ! } // }}} ! function SocketError($msg) // {{{ { dprint("DaemonSession::SocketError($msg)"); *************** *** 49,62 **** $this->Socket->Close(); $this->Daemon->Active = false; ! } ! function CloseClientStack() { foreach($this->ClientElementStack as $e) { $this->SocketWrite("</$e>\n"); } ! } ! function XMLError() { dprint("DaemonSession::XMLError()"); --- 49,62 ---- $this->Socket->Close(); $this->Daemon->Active = false; ! } // }}} ! function CloseClientStack() // {{{ { foreach($this->ClientElementStack as $e) { $this->SocketWrite("</$e>\n"); } ! } // }}} ! function XMLError() // {{{ { dprint("DaemonSession::XMLError()"); *************** *** 66,72 **** $this->SendToClient("Error",$s,array( id=>200 )); dprint($s); ! } ! function RcvData($data) { $r = xml_parse($this->XMLParser,$data); --- 66,72 ---- $this->SendToClient("Error",$s,array( id=>200 )); dprint($s); ! } // }}} ! function RcvData($data) // {{{ { $r = xml_parse($this->XMLParser,$data); *************** *** 74,91 **** if ($this->Error) { return false; } return true; ! } ! function EndOfData() { $r = xml_parse($this->XMLParser,"",true); if (!$r) $this->XMLError(); ! } ! function Handle_CharData($parser, $data) { $this->CharData .= $data; ! } ! function SendToClient($element, $data="", $args=array()) { dprint("DaemonSession::SendToClient($element, $data, $args)"); --- 74,91 ---- if ($this->Error) { return false; } return true; ! } // }}} ! function EndOfData() // {{{ { $r = xml_parse($this->XMLParser,"",true); if (!$r) $this->XMLError(); ! } // }}} ! function Handle_CharData($parser, $data) // {{{ { $this->CharData .= $data; ! } // }}} ! function SendToClient($element, $data="", $args=array()) // {{{ { dprint("DaemonSession::SendToClient($element, $data, $args)"); *************** *** 106,112 **** $this->SocketWrite($out); dprint("Sent:\n$out"); ! } ! function Handle_StartElement($parser, $name, $attrs) { dprint("Daemon::StartElement($parser, $name, $attrs)"); --- 106,112 ---- $this->SocketWrite($out); dprint("Sent:\n$out"); ! } // }}} ! function Handle_StartElement($parser, $name, $attrs) // {{{ { dprint("Daemon::StartElement($parser, $name, $attrs)"); *************** *** 115,118 **** --- 115,119 ---- while($once = true) { $once = false; + // First Element in the document (aka document element) {{{ if (count($this->ElementStack) == 0) { // first element *************** *** 132,136 **** --- 133,139 ---- break; } + // }}} + // Inside the SESSION element {{{ if ($this->ElementStack[0] == "SESSION") { if ($name == "ECHO") { *************** *** 148,158 **** break; } } array_push($this->ElementStack,$name); dprint("ElementStack: ".implode(", ",$this->ElementStack)); ! } ! function Handle_EndElement($parser, $name) { dprint("Daemon::EndElement($parser, $name)"); --- 151,162 ---- break; } + // }}} } array_push($this->ElementStack,$name); dprint("ElementStack: ".implode(", ",$this->ElementStack)); ! } // }}} ! function Handle_EndElement($parser, $name) // {{{ { dprint("Daemon::EndElement($parser, $name)"); *************** *** 186,196 **** } } ! } ! function Close() { $this->CloseClientStack(); xml_parser_free($this->XMLParser); ! } } --- 190,200 ---- } } ! } // }}} ! function Close() // {{{ { $this->CloseClientStack(); xml_parser_free($this->XMLParser); ! } // }}} } Index: Server.Class.php =================================================================== RCS file: /cvsroot/phpfwconfsys/Daemon-Alpha/Server.Class.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Server.Class.php 8 Jan 2003 02:50:54 -0000 1.3 --- Server.Class.php 8 Jan 2003 04:39:51 -0000 1.4 *************** *** 15,19 **** var $SIGNALHooks = array(); ! function Server($socket, &$handler, $prefork=10) { // assume the socket is already bound to and set to listen --- 15,19 ---- var $SIGNALHooks = array(); ! function Server($socket, &$handler, $prefork=10) // {{{ { // assume the socket is already bound to and set to listen *************** *** 21,27 **** $this->Socket = &$socket; $this->Handler = &$handler; ! } ! function Start() { dprint("Server::Start()"); --- 21,27 ---- $this->Socket = &$socket; $this->Handler = &$handler; ! } // }}} ! function Start() // {{{ { dprint("Server::Start()"); *************** *** 40,58 **** $this->Sentinel(); ! } ! function AddHook($sig, $handler) { @$this->SIGNALHooks[$sig] = $handler; ! } ! function RemoveHook($sig) { if (isset($this->SIGNALHooks[$sig])) { $this->SIGNALHooks[$sig] = null; } ! } ! function Sentinel() { dprint("Server::Sentinel()"); --- 40,58 ---- $this->Sentinel(); ! } // }}} ! function AddHook($sig, $handler) // {{{ { @$this->SIGNALHooks[$sig] = $handler; ! } // }}} ! function RemoveHook($sig) // {{{ { if (isset($this->SIGNALHooks[$sig])) { $this->SIGNALHooks[$sig] = null; } ! } // }}} ! function Sentinel() // {{{ { dprint("Server::Sentinel()"); *************** *** 74,82 **** } dprint("Server::Sentinel(): Reached End"); ! } ! ! function Parent_Handler($sig) ! { dprint("Server::Parent_Handler($sig)"); switch ($sig) --- 74,81 ---- } dprint("Server::Sentinel(): Reached End"); ! } // }}} ! function Parent_Handler($sig) // {{{ ! { dprint("Server::Parent_Handler($sig)"); switch ($sig) *************** *** 87,93 **** break; } ! } ! function Child_Handler($sig) { dprint("Server::Child_Handler($sig)"); --- 86,92 ---- break; } ! } // }}} ! function Child_Handler($sig) // {{{ { dprint("Server::Child_Handler($sig)"); *************** *** 119,125 **** } ! } ! function ForkWorker() { dprint("Server::ForkWorker()"); --- 118,124 ---- } ! } // }}} ! function ForkWorker() // {{{ { dprint("Server::ForkWorker()"); *************** *** 142,155 **** $this->StartListen(); } ! } ! function AddChild($pid) { array_push($this->Children,$pid); dprint("Child: $pid Added to Children List"); dprint("Children: ".implode(", ",$this->Children)); ! } ! function RemoveChild($pid) { dprint("RemoveChild($pid)"); --- 141,154 ---- $this->StartListen(); } ! } // }}} ! function AddChild($pid) // {{{ { array_push($this->Children,$pid); dprint("Child: $pid Added to Children List"); dprint("Children: ".implode(", ",$this->Children)); ! } // }}} ! function RemoveChild($pid) // {{{ { dprint("RemoveChild($pid)"); *************** *** 163,169 **** dprint("Removed PID: $pid from Children List"); dprint("Children: ".implode(", ",$this->Children)); ! } ! function Handle(&$Sock) { if (is_array($this->Handler)) { --- 162,168 ---- dprint("Removed PID: $pid from Children List"); dprint("Children: ".implode(", ",$this->Children)); ! } // }}} ! function Handle(&$Sock) // {{{ { if (is_array($this->Handler)) { *************** *** 176,182 **** $func(&$Sock); } ! } ! function StartListen() { $ChildSock =& $this->Socket->Accept(); --- 175,181 ---- $func(&$Sock); } ! } // }}} ! function StartListen() // {{{ { $ChildSock =& $this->Socket->Accept(); *************** *** 194,200 **** dprint("Ending Child Process."); exit; ! } ! function KillChildren($sig=SIGTERM, $wait=false) { dprint("Server::KillChildren($sig, $wait)"); --- 193,199 ---- dprint("Ending Child Process."); exit; ! } // }}} ! function KillChildren($sig=SIGTERM, $wait=false) // {{{ { dprint("Server::KillChildren($sig, $wait)"); *************** *** 208,219 **** } } ! } ! function Shutdown() { dprint("Server::Shutdown()"); $this->Running = false; $this->KillChildren(SIGUSR1,true); ! } } --- 207,218 ---- } } ! } // }}} ! function Shutdown() // {{{ { dprint("Server::Shutdown()"); $this->Running = false; $this->KillChildren(SIGUSR1,true); ! } // }}} } Index: Socket.Class.php =================================================================== RCS file: /cvsroot/phpfwconfsys/Daemon-Alpha/Socket.Class.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Socket.Class.php 8 Jan 2003 02:50:54 -0000 1.3 --- Socket.Class.php 8 Jan 2003 04:39:51 -0000 1.4 *************** *** 9,13 **** var $Valid = true; ! function Socket($domain) { echo "Debug: Socket::Socket($domain)\n"; --- 9,13 ---- var $Valid = true; ! function Socket($domain) // {{{ { echo "Debug: Socket::Socket($domain)\n"; *************** *** 30,35 **** } } ! function GetLastSocketError() { $errno = socket_last_error($this->Socket); --- 30,36 ---- } } + // }}} ! function GetLastSocketError() // {{{ { $errno = socket_last_error($this->Socket); *************** *** 38,49 **** return "Error $errno: ($errstr)"; } ! function GetLastErrorNumber() { $errno = socket_last_error($this->Socket); return $errno; } ! ! function Bind($address, $port = -1) { echo "Debug: Socket::Bind($address,$port)\n"; --- 39,52 ---- return "Error $errno: ($errstr)"; } + // }}} ! function GetLastErrorNumber() // {{{ { $errno = socket_last_error($this->Socket); return $errno; } ! // }}} ! ! function Bind($address, $port = -1) // {{{ { echo "Debug: Socket::Bind($address,$port)\n"; *************** *** 65,70 **** return true; } ! function Listen($backlog = 1) { echo "Debug: Socket::Listen($backlog)\n"; --- 68,74 ---- return true; } + // }}} ! function Listen($backlog = 1) // {{{ { echo "Debug: Socket::Listen($backlog)\n"; *************** *** 79,84 **** return true; } ! function &Accept() { echo "Debug: Socket::Accept()\n"; --- 83,89 ---- return true; } + // }}} ! function &Accept() // {{{ { echo "Debug: Socket::Accept()\n"; *************** *** 103,108 **** return new SocketClone($result); } ! function Write($msg) { echo "Debug: Socket::Write($msg)\n"; --- 108,114 ---- return new SocketClone($result); } + // }}} ! function Write($msg) // {{{ { echo "Debug: Socket::Write($msg)\n"; *************** *** 118,123 **** return $result; } ! function Read($num, &$buf, $type=PHP_BINARY_READ) { echo "Debug: Socket::Read($num, $type)\n"; --- 124,130 ---- return $result; } + // }}} ! function Read($num, &$buf, $type=PHP_BINARY_READ) // {{{ { echo "Debug: Socket::Read($num, $type)\n"; *************** *** 139,144 **** return strlen($buf); } ! function Close() { echo "Debug: Socket::Close()\n"; --- 146,152 ---- return strlen($buf); } + // }}} ! function Close() // {{{ { echo "Debug: Socket::Close()\n"; *************** *** 151,154 **** --- 159,163 ---- return true; } + // }}} } Index: Utility.php =================================================================== RCS file: /cvsroot/phpfwconfsys/Daemon-Alpha/Utility.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Utility.php 5 Jan 2003 07:12:00 -0000 1.1 --- Utility.php 8 Jan 2003 04:39:51 -0000 1.2 *************** *** 1,16 **** <?php ! function array_swap(&$array, $ind1, $ind2) { $tmp = &$array[$ind1]; $array[$ind1] = &$array[$ind2]; $array[$ind2] = &$tmp; ! } ! function dprint($str) { $pid = posix_getpid(); echo "DBG: ($pid): $str\n"; ! } --- 1,16 ---- <?php ! function array_swap(&$array, $ind1, $ind2) // {{{ { $tmp = &$array[$ind1]; $array[$ind1] = &$array[$ind2]; $array[$ind2] = &$tmp; ! } // }}} ! function dprint($str) // {{{ { $pid = posix_getpid(); echo "DBG: ($pid): $str\n"; ! } // }}} |