@@ 196-215 (lines=20) @@ | ||
193 | * @return string |
|
194 | * @throws \AppserverIo\Psr\Socket\SocketReadTimeoutException |
|
195 | */ |
|
196 | public function readLine($readLength = 1024, $receiveTimeout = null) |
|
197 | { |
|
198 | if ($receiveTimeout) { |
|
199 | // set timeout for read data fom client |
|
200 | @stream_set_timeout($this->getConnectionResource(), $receiveTimeout); |
|
201 | } |
|
202 | $line = @fgets($this->getConnectionResource(), $readLength); |
|
203 | ||
204 | // check if read error occured |
|
205 | if ($line === false) { |
|
206 | throw new SocketReadException(); |
|
207 | } |
|
208 | ||
209 | // check if timeout occurred |
|
210 | if (strlen($line) === 0) { |
|
211 | throw new SocketReadTimeoutException(); |
|
212 | } |
|
213 | ||
214 | return $line; |
|
215 | } |
|
216 | ||
217 | /** |
|
218 | * Reads the given length from connection resource |
|
@@ 228-246 (lines=19) @@ | ||
225 | * @throws \AppserverIo\Psr\Socket\SocketReadTimeoutException |
|
226 | * @throws \AppserverIo\Psr\Socket\SocketReadException |
|
227 | */ |
|
228 | public function read($readLength = 1024, $receiveTimeout = null) |
|
229 | { |
|
230 | if ($receiveTimeout) { |
|
231 | // set timeout for read data fom client |
|
232 | @stream_set_timeout($this->getConnectionResource(), $receiveTimeout); |
|
233 | } |
|
234 | // read in line from client |
|
235 | $line = @fread($this->getConnectionResource(), $readLength); |
|
236 | // check if false is response |
|
237 | if (false === $line) { |
|
238 | // throw new socket exception |
|
239 | throw new SocketReadException(); |
|
240 | } |
|
241 | // check if timeout occurred |
|
242 | if (strlen($line) === 0) { |
|
243 | throw new SocketReadTimeoutException(); |
|
244 | } |
|
245 | return $line; |
|
246 | } |
|
247 | ||
248 | /** |
|
249 | * Writes the given message to the connection resource. |