]> git.mxchange.org Git - hub.git/blob - application/hub/main/helper/connection/class_BaseConnectionHelper.php
The final hash must be used as an array key for serial numbers, else some packages...
[hub.git] / application / hub / main / helper / connection / class_BaseConnectionHelper.php
1 <?php
2 /**
3  * A general ConnectionHelper class
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
8  * @license             GNU GPL 3.0 or any newer version
9  * @link                http://www.shipsimu.org
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24 class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable, ProtocolHandler {
25         // Exception codes
26         const EXCEPTION_UNSUPPORTED_ERROR_HANDLER = 0x9100;
27
28         /**
29          * Connection type 'incoming'
30          */
31         const CONNECTION_TYPE_INCOMING = 'incoming';
32
33         /**
34          * Connection type 'outgoing'
35          */
36         const CONNECTION_TYPE_OUTGOING = 'outgoing';
37
38         /**
39          * Connection type 'server'
40          */
41         const CONNECTION_TYPE_SERVER   = 'server';
42
43         /**
44          * Protocol used
45          */
46         private $protocol = 'invalid';
47
48         /**
49          * Port number used
50          */
51         private $port = 0;
52
53         /**
54          * (IP) Adress used
55          */
56         private $address = 0;
57
58         /**
59          * Sent data in bytes
60          */
61         private $sentData = 0;
62
63         /**
64          * Difference
65          */
66         private $diff = 0;
67
68         /**
69          * Whether this connection is initialized
70          */
71         private $isInitialized = FALSE;
72
73         /**
74          * Whether this connection is shutted down
75          */
76         private $shuttedDown = FALSE;
77
78         /**
79          * Currently queued chunks
80          */
81         private $queuedChunks = array();
82
83         /**
84          * Current final hash
85          */
86         private $currentFinalHash = '';
87
88         /**
89          * Protected constructor
90          *
91          * @param       $className      Name of the class
92          * @return      void
93          */
94         protected function __construct ($className) {
95                 // Call parent constructor
96                 parent::__construct($className);
97
98                 // Initialize output stream
99                 $streamInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_output_stream_class');
100
101                 // And add it to this connection helper
102                 $this->setOutputStreamInstance($streamInstance);
103
104                 // Init state which sets the state to 'init'
105                 $this->initState();
106
107                 // Register this connection helper
108                 Registry::getRegistry()->addInstance('connection', $this);
109
110                 // Get the fragmenter instance
111                 $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package');
112
113                 // Set it here
114                 $this->setFragmenterInstance($fragmenterInstance);
115         }
116
117         /**
118          * Getter for real class name, overwrites generic method and is final
119          *
120          * @return      $class  Name of this class
121          */
122         public final function __toString () {
123                 // Class name representation
124                 $class = self::getConnectionClassName($this->getAddress(), $this->getPort(), parent::__toString());
125
126                 // Return it
127                 return $class;
128         }
129
130         /**
131          * Getter for port number to satify ProtocolHandler
132          *
133          * @return      $port   The port number
134          */
135         public final function getPort () {
136                 return $this->port;
137         }
138
139         /**
140          * Setter for port number to satify ProtocolHandler
141          *
142          * @param       $port   The port number
143          * @return      void
144          */
145         protected final function setPort ($port) {
146                 $this->port = $port;
147         }
148
149         /**
150          * Getter for protocol
151          *
152          * @return      $protocol       Used protocol
153          */
154         public final function getProtocol () {
155                 return $this->protocol;
156         }
157
158         /**
159          * Setter for protocol
160          *
161          * @param       $protocol       Used protocol
162          * @return      void
163          */
164         protected final function setProtocol ($protocol) {
165                 $this->protocol = $protocol;
166         }
167
168         /**
169          * Getter for IP address
170          *
171          * @return      $address        The IP address
172          */
173         public final function getAddress () {
174                 return $this->address;
175         }
176
177         /**
178          * Setter for IP address
179          *
180          * @param       $address        The IP address
181          * @return      void
182          */
183         protected final function setAddress ($address) {
184                 $this->address = $address;
185         }
186
187         /**
188          * Initializes the current connection
189          *
190          * @return      void
191          * @throws      SocketOptionException   If setting any socket option fails
192          */
193         protected function initConnection () {
194                 // Get socket resource
195                 $socketResource = $this->getSocketResource();
196
197                 // Set the option to reuse the port
198                 if (!socket_set_option($socketResource, SOL_SOCKET, SO_REUSEADDR, 1)) {
199                         // Handle this socket error with a faked recipientData array
200                         $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
201
202                         // And throw again
203                         // @TODO Move this to the socket error handler
204                         throw new SocketOptionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
205                 } // END - if
206
207                 /*
208                  * Set socket to non-blocking mode before trying to establish a link to
209                  * it. This is now the default behaviour for all connection helpers who
210                  * call initConnection(); .
211                  */
212                 if (!socket_set_nonblock($socketResource)) {
213                         // Handle this socket error with a faked recipientData array
214                         $helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
215
216                         // And throw again
217                         throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
218                 } // END - if
219
220                 // Last step: mark connection as initialized
221                 $this->isInitialized = TRUE;
222         }
223
224         /**
225          * Attempts to connect to a peer by given IP number and port from a valid
226          * recipientData array with currently configured timeout.
227          *
228          * @param       $recipientData  A valid recipient data array, 0=IP; 1=PORT
229          * @return      $isConnected    Whether the connection went fine
230          * @see         Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code
231          * @todo        Rewrite the while() loop to a iterator to not let the software stay very long here
232          */
233         protected function connectToPeerByRecipientData (array $recipientData) {
234                 // Only call this if the connection is initialized by initConnection()
235                 assert($this->isInitialized === TRUE);
236
237                 // Get current time
238                 $time = time();
239
240                 // "Cache" socket resource and timeout config
241                 $socketResource = $this->getSocketResource();
242                 $timeout = $this->getConfigInstance()->getConfigEntry('socket_timeout_seconds');
243
244                 // Debug output
245                 self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Trying to connect to ' . $recipientData[0] . ':' . $recipientData[1] . ' with socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' ...');
246
247                 // Try to connect until it is connected
248                 while ($isConnected = !@socket_connect($socketResource, $recipientData[0], $recipientData[1])) {
249                         // Get last socket error
250                         $socketError = socket_last_error($socketResource);
251
252                         // Skip any errors which may happen on non-blocking connections
253                         if (($socketError == SOCKET_EINPROGRESS) || ($socketError == SOCKET_EALREADY)) {
254                                 // Now, is that attempt within parameters?
255                                 if ((time() - $time) >= $timeout) {
256                                         // Didn't work within timeout
257                                         $isConnected = FALSE;
258                                         break;
259                                 } // END - if
260
261                                 // Sleep about one second
262                                 $this->idle(1000);
263                         } elseif ($socketError != 0) {
264                                 // Stop on everything else pronto
265                                 $isConnected = FALSE;
266                                 break;
267                         }
268                 } // END - while
269
270                 // Is the peer connected?
271                 if ($isConnected === TRUE) {
272                         // Connection is fully established here, so change the state.
273                         PeerStateFactory::createPeerStateInstanceByName('connected', $this);
274                 } else {
275                         /*
276                          * There was a problem connecting to the peer (this state is a meta
277                          * state until the error handler has found the real cause).
278                          */
279                         PeerStateFactory::createPeerStateInstanceByName('problem', $this);
280                 }
281
282                 // Return status
283                 return $isConnected;
284         }
285
286         /**
287          * Static "getter" for this connection class' name
288          *
289          * @param       $address        IP address
290          * @param       $port           Port number
291          * @param       $className      Original class name
292          * @return      $class          Expanded class name
293          */
294         public static function getConnectionClassName ($address, $port, $className) {
295                 // Construct it
296                 $class = $address . ':' . $port . ':' . $className;
297
298                 // ... and return it
299                 return $class;
300         }
301
302         /**
303          * Initializes the peer's state which sets it to 'init'
304          *
305          * @return      void
306          */
307         private function initState() {
308                 /*
309                  * Get the state factory and create the initial state, we don't need
310                  * the state instance here
311                  */
312                 PeerStateFactory::createPeerStateInstanceByName('init', $this);
313         }
314
315         /**
316          * "Getter" for raw data from a package array. A fragmenter is used which
317          * will returns us only so many raw data which fits into the back buffer.
318          * The rest is being held in a back-buffer and waits there for the next
319          * cycle and while be then sent.
320          *
321          * This method does 4 simple steps:
322          * 1) Aquire fragmenter object instance from the factory
323          * 2) Handle over the package data array to the fragmenter
324          * 3) Request a chunk
325          * 4) Finally return the chunk (array) to the caller
326          *
327          * @param       $packageData    Raw package data array
328          * @return      $chunkData              Raw data chunk
329          */
330         private function getRawDataFromPackageArray (array $packageData) {
331                 // Debug message
332                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: currentFinalHash=' . $this->currentFinalHash);
333
334                 // Make sure the final hash is set
335                 assert((is_string($this->currentFinalHash)) && (!empty($this->currentFinalHash)));
336
337                 // Get the next raw data chunk from the fragmenter
338                 $rawDataChunk = $this->getFragmenterInstance()->getNextRawDataChunk($this->currentFinalHash);
339
340                 // Debug message
341                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: rawDataChunk=' . print_r($rawDataChunk, TRUE));
342
343                 // Get chunk hashes and chunk data
344                 $chunkHashes = array_keys($rawDataChunk);
345                 $chunkData   = array_values($rawDataChunk);
346
347                 // Is the required data there?
348                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: chunkHashes[]=' . count($chunkHashes) . ',chunkData[]=' . count($chunkData));
349                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('chunkData='.print_r($chunkData, TRUE));
350                 if ((isset($chunkHashes[0])) && (isset($chunkData[0]))) {
351                         // Remember this chunk as queued
352                         $this->queuedChunks[$chunkHashes[0]] = $chunkData[0];
353
354                         // Return the raw data
355                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Returning ' . strlen($chunkData[0]) . ' bytes from ' . __METHOD__ . ' ...');
356                         return $chunkData[0];
357                 } else {
358                         // Return zero string
359                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Returning zero bytes from ' . __METHOD__ . '!');
360                         return '';
361                 }
362         }
363
364         /**
365          * "Accept" a visitor by simply calling it back
366          *
367          * @param       $visitorInstance        A Visitor instance
368          * @return      void
369          */
370         protected final function accept (Visitor $visitorInstance) {
371                 // Just call the visitor
372                 $visitorInstance->visitConnectionHelper($this);
373         }
374
375         /**
376          * Sends raw package data to the recipient
377          *
378          * @param       $packageData            Raw package data
379          * @return      $totalSentBytes         Total sent bytes to the peer
380          * @throws      InvalidSocketException  If we got a problem with this socket
381          */
382         public function sendRawPackageData (array $packageData) {
383                 // The helper's state must be 'connected'
384                 $this->getStateInstance()->validatePeerStateConnected();
385
386                 // Implode the package data array and fragement the resulting string, returns the final hash
387                 $finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageData, $this);
388                 if ($finalHash !== TRUE) {
389                         // Debug message
390                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Setting finalHash=' . $finalHash . ',currentFinalHash[' . gettype($this->currentFinalHash) . ']=' . $this->currentFinalHash);
391
392                         // Set final hash
393                         $this->currentFinalHash = $finalHash;
394                 } // END - if
395
396                 // Reset serial number
397                 $this->getFragmenterInstance()->resetSerialNumber($this->currentFinalHash);
398
399                 // Cache buffer length
400                 $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length');
401
402                 // Init variables
403                 $rawData        = '';
404                 $dataStream     = ' ';
405                 $totalSentBytes = 0;
406
407                 // Fill sending buffer with data
408                 while (strlen($dataStream) > 0) {
409                         // Debug message
410                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE));
411
412                         // Convert the package data array to a raw data stream
413                         $dataStream = $this->getRawDataFromPackageArray($packageData);
414                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Adding ' . strlen($dataStream) . ' bytes to the sending buffer ...');
415                         $rawData .= $dataStream;
416                 } // END - while
417
418                 // Nothing to sent is bad news, so assert on it
419                 assert(strlen($rawData) > 0);
420
421                 // Encode the raw data with our output-stream
422                 $encodedData = $this->getOutputStreamInstance()->streamData($rawData);
423
424                 // Debug message
425                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: rawData()=' . strlen($rawData) . ',encodedData()=' . strlen($encodedData));
426
427                 // Calculate difference
428                 $this->diff = $bufferSize - strlen($encodedData);
429
430                 // Get socket resource
431                 $socketResource = $this->getSocketResource();
432
433                 // Init sent bytes
434                 $sentBytes = 0;
435
436                 // Deliver all data
437                 while ($sentBytes !== FALSE) {
438                         // And deliver it
439                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Sending out ' . strlen($encodedData) . ' bytes,bufferSize=' . $bufferSize . ',diff=' . $this->diff);
440
441                         if ($this->diff >= 0) {
442                                 // Send all out (encodedData is smaller than or equal buffer size)
443                                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedData, 0, ($bufferSize - $this->diff))));
444                                 $sentBytes = socket_write($socketResource, $encodedData, ($bufferSize - $this->diff));
445                         } else {
446                                 // Send buffer size out
447                                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: MD5=' . md5(substr($encodedData, 0, $bufferSize)));
448                                 $sentBytes = socket_write($socketResource, $encodedData, $bufferSize);
449                         }
450
451                         // If there was an error, we don't continue here
452                         if ($sentBytes === FALSE) {
453                                 // Handle the error with a faked recipientData array
454                                 $this->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
455
456                                 // And throw it
457                                 throw new InvalidSocketException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
458                         } elseif (($sentBytes == 0) && (strlen($encodedData) > 0)) {
459                                 // Nothing sent means we are done
460                                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
461                                 break;
462                         }
463
464                         // The difference between sent bytes and length of raw data should not go below zero
465                         assert((strlen($encodedData) - $sentBytes) >= 0);
466
467                         // Add total sent bytes
468                         $totalSentBytes += $sentBytes;
469
470                         // Cut out the last unsent bytes
471                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Sent out ' . $sentBytes . ' of ' . strlen($encodedData) . ' bytes ...');
472                         $encodedData = substr($encodedData, $sentBytes);
473
474                         // Calculate difference again
475                         $this->diff = $bufferSize - strlen($encodedData);
476
477                         // Can we abort?
478                         if (strlen($encodedData) <= 0) {
479                                 // Abort here, all sent!
480                                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
481                                 break;
482                         } // END - if
483                 } // END - while
484
485                 // Return sent bytes
486                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: totalSentBytes=' . $totalSentBytes . ',diff=' . $this->diff);
487                 return $totalSentBytes;
488         }
489
490         /**
491          * Marks this connection as shutted down
492          *
493          * @return      void
494          */
495         protected final function markConnectionShuttedDown () {
496                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $this->__toString() . ' has been marked as shutted down');
497                 $this->shuttedDown = TRUE;
498
499                 // And remove the (now invalid) socket
500                 $this->setSocketResource(FALSE);
501         }
502
503         /**
504          * Getter for shuttedDown
505          *
506          * @return      $shuttedDown    Whether this connection is shutted down
507          */
508         public final function isShuttedDown () {
509                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown));
510                 return $this->shuttedDown;
511         }
512
513         // ************************************************************************
514         //                 Socket error handler call-back methods
515         // ************************************************************************
516
517         /**
518          * Handles socket error 'connection timed out', but does not clear it for
519          * later debugging purposes.
520          *
521          * @param       $socketResource         A valid socket resource
522          * @param       $recipientData          An array with two elements: 0=IP number, 1=port number
523          * @return      void
524          * @throws      SocketConnectionException       The connection attempts fails with a time-out
525          */
526         protected function socketErrorConnectionTimedOutHandler ($socketResource, array $recipientData) {
527                 // Get socket error code for verification
528                 $socketError = socket_last_error($socketResource);
529
530                 // Get error message
531                 $errorMessage = socket_strerror($socketError);
532
533                 // Shutdown this socket
534                 $this->shutdownSocket($socketResource);
535
536                 // Throw it again
537                 throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
538         }
539
540         /**
541          * Handles socket error 'resource temporary unavailable', but does not
542          * clear it for later debugging purposes.
543          *
544          * @param       $socketResource         A valid socket resource
545          * @param       $recipientData          An array with two elements: 0=IP number, 1=port number
546          * @return      void
547          * @throws      SocketConnectionException       The connection attempts fails with a time-out
548          */
549         protected function socketErrorResourceUnavailableHandler ($socketResource, array $recipientData) {
550                 // Get socket error code for verification
551                 $socketError = socket_last_error($socketResource);
552
553                 // Get error message
554                 $errorMessage = socket_strerror($socketError);
555
556                 // Shutdown this socket
557                 $this->shutdownSocket($socketResource);
558
559                 // Throw it again
560                 throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
561         }
562
563         /**
564          * Handles socket error 'connection refused', but does not clear it for
565          * later debugging purposes.
566          *
567          * @param       $socketResource         A valid socket resource
568          * @param       $recipientData          An array with two elements: 0=IP number, 1=port number
569          * @return      void
570          * @throws      SocketConnectionException       The connection attempts fails with a time-out
571          */
572         protected function socketErrorConnectionRefusedHandler ($socketResource, array $recipientData) {
573                 // Get socket error code for verification
574                 $socketError = socket_last_error($socketResource);
575
576                 // Get error message
577                 $errorMessage = socket_strerror($socketError);
578
579                 // Shutdown this socket
580                 $this->shutdownSocket($socketResource);
581
582                 // Throw it again
583                 throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
584         }
585
586         /**
587          * Handles socket error 'no route to host', but does not clear it for later
588          * debugging purposes.
589          *
590          * @param       $socketResource         A valid socket resource
591          * @param       $recipientData          An array with two elements: 0=IP number, 1=port number
592          * @return      void
593          * @throws      SocketConnectionException       The connection attempts fails with a time-out
594          */
595         protected function socketErrorNoRouteToHostHandler ($socketResource, array $recipientData) {
596                 // Get socket error code for verification
597                 $socketError = socket_last_error($socketResource);
598
599                 // Get error message
600                 $errorMessage = socket_strerror($socketError);
601
602                 // Shutdown this socket
603                 $this->shutdownSocket($socketResource);
604
605                 // Throw it again
606                 throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
607         }
608
609         /**
610          * Handles socket error 'operation already in progress' which happens in
611          * method connectToPeerByRecipientData() on timed out connection
612          * attempts.
613          *
614          * @param       $socketResource         A valid socket resource
615          * @param       $recipientData          An array with two elements: 0=IP number, 1=port number
616          * @return      void
617          * @throws      SocketConnectionException       The connection attempts fails with a time-out
618          */
619         protected function socketErrorOperationAlreadyProgressHandler ($socketResource, array $recipientData) {
620                 // Get socket error code for verification
621                 $socketError = socket_last_error($socketResource);
622
623                 // Get error message
624                 $errorMessage = socket_strerror($socketError);
625
626                 // Half-shutdown this socket (see there for difference to shutdownSocket())
627                 $this->halfShutdownSocket($socketResource);
628
629                 // Throw it again
630                 throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
631         }
632
633         /**
634          * Handles socket "error" 'operation now in progress' which can be safely
635          * passed on with non-blocking connections.
636          *
637          * @param       $socketResource         A valid socket resource
638          * @param       $recipientData          An array with two elements: 0=IP number, 1=port number
639          * @return      void
640          */
641         protected function socketErrorOperationInProgressHandler ($socketResource, array $recipientData) {
642                 self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Operation is now in progress, this is usual for non-blocking connections and is no bug.');
643         }
644 }
645
646 // [EOF]
647 ?>