1 | <?php |
||
74 | class SimpleSocket extends SimpleStickyError { |
||
75 | var $_handle; |
||
76 | var $_is_open = false; |
||
77 | var $_sent = ''; |
||
78 | var $lock_size; |
||
79 | |||
80 | /** |
||
81 | * Opens a socket for reading and writing. |
||
82 | * @param string $host Hostname to send request to. |
||
83 | * @param integer $port Port on remote machine to open. |
||
84 | * @param integer $timeout Connection timeout in seconds. |
||
85 | * @param integer $block_size Size of chunk to read. |
||
86 | * @access public |
||
87 | */ |
||
88 | function SimpleSocket($host, $port, $timeout, $block_size = 255) { |
||
89 | $this->SimpleStickyError(); |
||
90 | if (! ($this->_handle = $this->_openSocket($host, $port, $error_number, $error, $timeout))) { |
||
91 | $this->_setError("Cannot open [$host:$port] with [$error] within [$timeout] seconds"); |
||
92 | return; |
||
93 | } |
||
94 | $this->_is_open = true; |
||
95 | $this->_block_size = $block_size; |
||
96 | SimpleTestCompatibility::setTimeout($this->_handle, $timeout); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Writes some data to the socket and saves alocal copy. |
||
101 | * @param string $message String to send to socket. |
||
102 | * @return boolean True if successful. |
||
103 | * @access public |
||
104 | */ |
||
105 | function write($message) { |
||
121 | |||
122 | /** |
||
123 | * Reads data from the socket. The error suppresion |
||
124 | * is a workaround for PHP4 always throwing a warning |
||
125 | * with a secure socket. |
||
126 | * @return integer/boolean Incoming bytes. False |
||
127 | * on error. |
||
128 | * @access public |
||
129 | */ |
||
130 | function read() { |
||
141 | |||
142 | /** |
||
143 | * Accessor for socket open state. |
||
144 | * @return boolean True if open. |
||
145 | * @access public |
||
146 | */ |
||
147 | function isOpen() { |
||
150 | |||
151 | /** |
||
152 | * Closes the socket preventing further reads. |
||
153 | * Cannot be reopened once closed. |
||
154 | * @return boolean True if successful. |
||
155 | * @access public |
||
156 | */ |
||
157 | function close() { |
||
161 | |||
162 | /** |
||
163 | * Accessor for content so far. |
||
164 | * @return string Bytes sent only. |
||
165 | * @access public |
||
166 | */ |
||
167 | function getSent() { |
||
170 | |||
171 | /** |
||
172 | * Actually opens the low level socket. |
||
173 | * @param string $host Host to connect to. |
||
174 | * @param integer $port Port on host. |
||
175 | * @param integer $error_number Recipient of error code. |
||
176 | * @param string $error Recipoent of error message. |
||
177 | * @param integer $timeout Maximum time to wait for connection. |
||
178 | * @access protected |
||
179 | */ |
||
180 | function _openSocket($host, $port, &$error_number, &$error, $timeout) { |
||
183 | } |
||
184 | |||
217 |