00001 <?php
00002
00003
00004
00005
00006
00007
00008 class Socket_SocketPool {
00009
00010
00011
00012
00013
00014 protected $sockets;
00015
00016
00017
00018
00019
00020 function __construct() {
00021 $this->sockets = array();
00022 }
00023
00024
00025
00026
00027
00028 function __destruct() {
00029 unset($this->sockets);
00030 }
00031
00032
00033
00034
00035
00036 public function countSockets() {
00037 return count($this->sockets);
00038 }
00039
00040
00041
00042
00043
00044
00045 public function addSocket($add_socket) {
00046 array_push($this->sockets, $add_socket);
00047 }
00048
00049
00050
00051
00052
00053
00054
00055 public function removeSocket($remove_socket) {
00056 foreach($this->sockets AS $key=>$socket) {
00057 if($socket !== $remove_socket) {
00058 continue;
00059 } else {
00060 unset($socket);
00061 unset($this->sockets[$key]);
00062 break;
00063 }
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 public function createTcpSocket($IPv6 = FALSE) {
00074 $Domain = ($IPv6) ? AF_INET6 : AF_INET;
00075 $socket = socket_create($Domain, SOCK_STREAM, SOL_TCP);
00076 socket_set_block($socket);
00077 if($socket === FALSE) throw new Exception_SocketException("socket_create() failed!", 1290273709);
00078 $this->addSocket($socket);
00079 return $socket;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 public function select($read, $write, $except, $timeout = NULL) {
00092 $n = socket_select($read, $write, $except, $timeout);
00093 if($n === FALSE) throw new Exception_SocketException("socket_select() failed!", 1290273693);
00094 if($n === 0) return array("read" => array(), "write" => array(), "except" => array());
00095 return array("read" => $read, "write" => $write, "except" => $except);
00096 }
00097
00098
00099 }
00100 ?>