equal
deleted
inserted
replaced
2073 |
2073 |
2074 function accept() |
2074 function accept() |
2075 { |
2075 { |
2076 // the goal of a custom accept() with *_select() is to tick every 200ms to allow signals. |
2076 // the goal of a custom accept() with *_select() is to tick every 200ms to allow signals. |
2077 foreach ( $this->sock as $sock ) |
2077 foreach ( $this->sock as $sock ) |
2078 { |
|
2079 stream_set_blocking($sock, 1); |
2078 stream_set_blocking($sock, 1); |
2080 $timeout = 200000; |
2079 $timeout = 200000; |
2081 $selection = @stream_select($r = array($sock), $w = array($sock), $e = array($sock), 0, $timeout); |
2080 $r = $this->sock; |
2082 if ( !$selection ) |
2081 $selection = @stream_select($r, $w = array($sock), $e = array($sock), 0, $timeout); |
2083 { |
2082 if ( !$selection ) |
2084 return false; |
2083 { |
2085 } |
2084 return false; |
2086 $remote = stream_socket_accept($sock); |
2085 } |
2087 $return = new Socket_Stream(); |
2086 $remote = stream_socket_accept($r[0]); |
2088 $return->sock = $remote; |
2087 $return = new Socket_Stream(); |
2089 $return->socket_initted = true; |
2088 $return->sock = $remote; |
2090 return $return; |
2089 $return->socket_initted = true; |
2091 } |
2090 return $return; |
2092 } |
2091 } |
2093 |
2092 |
2094 function soft_shutdown() |
2093 function soft_shutdown() |
2095 { |
2094 { |
2096 fclose($this->sock); |
2095 fclose($this->sock); |
2118 } |
2117 } |
2119 |
2118 |
2120 function get_peer_info(&$addr, &$port) |
2119 function get_peer_info(&$addr, &$port) |
2121 { |
2120 { |
2122 $peer = stream_socket_get_name($this->sock, true); |
2121 $peer = stream_socket_get_name($this->sock, true); |
2123 list($addr, $port) = explode(':', $peer); |
2122 $addr = substr($peer, 0, strrpos($peer, ':')); |
|
2123 $port = substr($peer, strrpos($peer, ':') + 1); |
2124 } |
2124 } |
2125 |
2125 |
2126 function write($data) |
2126 function write($data) |
2127 { |
2127 { |
2128 return @fwrite($this->sock, $data); |
2128 return @fwrite($this->sock, $data); |