Moved some code from TcpListener and made it a bit more generic, maybe just enough.
[core.git] / inc / main / classes / listener / class_BaseListener.php
1 <?php
2 /**
3  * A general listener class
4  *
5  * @author              Roland Haeder <webmaster@shipsimu.org>
6  * @version             0.0.0
7  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core 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 BaseListener extends BaseFrameworkSystem implements Visitable {
25         // Exception code constants
26         const EXCEPTION_INVALID_SOCKET                   = 0xa00;
27         const EXCEPTION_SOCKET_ALREADY_REGISTERED        = 0xa01;
28         const EXCEPTION_SOCKET_CREATION_FAILED           = 0xa02;
29         const EXCEPTION_NO_SOCKET_ERROR                  = 0xa03;
30         const EXCEPTION_CONNECTION_ALREADY_REGISTERED    = 0xa04;
31         const EXCEPTION_UNEXPECTED_PACKAGE_STATUS        = 0xa05;
32         const EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER = 0xa06;
33         const EXCEPTION_FINAL_CHUNK_VERIFICATION         = 0xa07;
34         const EXCEPTION_INVALID_DATA_CHECKSUM            = 0xa08;
35
36         /**
37          * Address (IP mostly) we shall listen on
38          */
39         private $listenAddress = '0.0.0.0'; // This is the default and listens on all interfaces
40
41         /**
42          * Port we shall listen on (or wait for incoming data)
43          */
44         private $listenPort = 0; // This port MUST be changed by your application
45
46         /**
47          * Whether we are in blocking or non-blocking mode (default: non-blocking
48          */
49         private $blockingMode = FALSE;
50
51         /**
52          * A peer pool instance
53          */
54         private $poolInstance = NULL;
55
56         /**
57          * Protected constructor
58          *
59          * @param       $className      Name of the class
60          * @return      void
61          */
62         protected function __construct ($className) {
63                 // Call parent constructor
64                 parent::__construct($className);
65         }
66
67         /**
68          * Checks whether the given socket resource is a server socket
69          *
70          * @param       $socketResource         A valid socket resource
71          * @return      $isServerSocket         Whether the socket resource is a server socket
72          */
73         protected function isServerSocketResource ($socketResource) {
74                 // Check it
75                 $isServerSocket = ((is_resource($socketResource)) && (!@socket_getpeername($socketResource, $peerName)));
76
77                 // We need to clear the error here if it is a resource
78                 if ($isServerSocket === TRUE) {
79                         // Clear the error
80                         //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('socketResource[]=' . gettype($socketResource));
81                         socket_clear_error($socketResource);
82                 } // END - if
83
84                 // Check peer name, it must be empty
85                 $isServerSocket = (($isServerSocket) && (empty($peerName)));
86
87                 // Return result
88                 return $isServerSocket;
89         }
90
91         /**
92          * Setter for listen address
93          *
94          * @param       $listenAddress  The address this listener should listen on
95          * @return      void
96          */
97         protected final function setListenAddress ($listenAddress) {
98                 $this->listenAddress = (string) $listenAddress;
99         }
100
101         /**
102          * Getter for listen address
103          *
104          * @return      $listenAddress  The address this listener should listen on
105          */
106         public final function getListenAddress () {
107                 return $this->listenAddress;
108         }
109
110         /**
111          * Setter for listen port
112          *
113          * @param       $listenPort             The port this listener should listen on
114          * @return      void
115          */
116         protected final function setListenPort ($listenPort) {
117                 $this->listenPort = (int) $listenPort;
118         }
119
120         /**
121          * Getter for listen port
122          *
123          * @return      $listenPort             The port this listener should listen on
124          */
125         public final function getListenPort () {
126                 return $this->listenPort;
127         }
128
129         /**
130          * "Setter" to set listen address from configuration entry
131          *
132          * @param       $configEntry    The configuration entry holding our listen address
133          * @return      void
134          */
135         public final function setListenAddressByConfiguration ($configEntry) {
136                 $this->setListenAddress($this->getConfigInstance()->getConfigEntry($configEntry));
137         }
138
139         /**
140          * "Setter" to set listen port from configuration entry
141          *
142          * @param       $configEntry    The configuration entry holding our listen port
143          * @return      void
144          */
145         public final function setListenPortByConfiguration ($configEntry) {
146                 $this->setListenPort($this->getConfigInstance()->getConfigEntry($configEntry));
147         }
148
149         /**
150          * Setter for blocking-mode
151          *
152          * @param       $blockingMode   Whether blocking-mode is disabled (default) or enabled
153          * @return      void
154          */
155         protected final function setBlockingMode ($blockingMode) {
156                 $this->blockingMode = (boolean) $blockingMode;
157         }
158
159         /**
160          * Checks whether blocking-mode is enabled or disabled
161          *
162          * @return      $blockingMode   Whether blocking mode is disabled or enabled
163          */
164         public final function isBlockingModeEnabled () {
165                 return $this->blockingMode;
166         }
167
168         /**
169          * Setter for peer pool instance
170          *
171          * @param       $poolInstance   The peer pool instance we shall set
172          * @return      void
173          */
174         protected final function setPoolInstance (PoolablePeer $poolInstance) {
175                 $this->poolInstance = $poolInstance;
176         }
177
178         /**
179          * Getter for peer pool instance
180          *
181          * @return      $poolInstance   The peer pool instance we shall set
182          */
183         public final function getPoolInstance () {
184                 return $this->poolInstance;
185         }
186
187         /**
188          * Getter for connection type
189          *
190          * @return      $connectionType         Connection type for this listener
191          */
192         public final function getConnectionType () {
193                 // Wrap the real getter
194                 return $this->getProtocolName();
195         }
196
197         /**
198          * Registeres the given socket resource for "this" listener instance. This
199          * will be done in a seperate class to allow package writers to use it
200          * again.
201          *
202          * @param       $socketResource         A valid server socket resource
203          * @return      void
204          * @throws      InvalidServerSocketException            If the given resource is no server socket
205          * @throws      SocketAlreadyRegisteredException        If the given resource is already registered
206          */
207         protected function registerServerSocketResource ($socketResource) {
208                 // First check if it is valid
209                 if (!$this->isServerSocketResource($socketResource)) {
210                         // No server socket
211                         throw new InvalidServerSocketException(array($this, $socketResource), self::EXCEPTION_INVALID_SOCKET);
212                 } elseif ($this->isServerSocketRegistered($socketResource)) {
213                         // Already registered
214                         throw new SocketAlreadyRegisteredException($this, self::EXCEPTION_SOCKET_ALREADY_REGISTERED);
215                 }
216
217                 // Get a socket registry instance (singleton)
218                 $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
219
220                 // Get a connection info instance
221                 $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
222
223                 // Will the info instance with listener data
224                 $infoInstance->fillWithListenerInformation($this);
225
226                 // Register the socket
227                 $registryInstance->registerSocket($infoInstance, $socketResource);
228
229                 // And set it here
230                 $this->setSocketResource($socketResource);
231         }
232
233         /**
234          * Checks whether given socket resource is registered in socket registry
235          *
236          * @param       $socketResource         A valid server socket resource
237          * @return      $isRegistered           Whether given server socket is registered
238          */
239         protected function isServerSocketRegistered ($socketResource) {
240                 // Get a socket registry instance (singleton)
241                 $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
242
243                 // Get a connection info instance
244                 $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
245
246                 // Will the info instance with listener data
247                 $infoInstance->fillWithListenerInformation($this);
248
249                 // Check it
250                 $isRegistered = $registryInstance->isSocketRegistered($infoInstance, $socketResource);
251
252                 // Return result
253                 return $isRegistered;
254         }
255
256         /**
257          * Accepts the visitor to process the visit "request"
258          *
259          * @param       $visitorInstance        An instance of a Visitor class
260          * @return      void
261          */
262         public function accept (Visitor $visitorInstance) {
263                 // Debug message
264                 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
265
266                 // Visit this listener
267                 $visitorInstance->visitListener($this);
268
269                 // Visit the pool if set
270                 if ($this->getPoolInstance() instanceof Poolable) {
271                         $this->getPoolInstance()->accept($visitorInstance);
272                 } // END - if
273
274                 // Debug message
275                 //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
276         }
277
278         /**
279          * Monitors incoming raw data from the handler and transfers it to the
280          * given receiver instance. This method should not be called, please call
281          * the decorator's version instead to separator node/client traffic.
282          *
283          * @return      void
284          * @throws      UnsupportedOperatorException    If this method is called by a mistake
285          */
286         public function monitorIncomingRawData () {
287                 throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
288         }
289
290         /**
291          * Constructs a callable method name from given socket error code. If the
292          * method is not found, a generic one is used.
293          *
294          * @param       $errorCode              Error code from socket_last_error()
295          * @return      $handlerName    Call-back method name for the error handler
296          * @throws      UnsupportedSocketErrorHandlerException If the error handler is not implemented
297          */
298         protected function getSocketErrorHandlerFromCode ($errorCode) {
299                 // Create a name from translated error code
300                 $handlerName = 'socketError' . self::convertToClassName($this->translateSocketErrorCodeToName($errorCode)) . 'Handler';
301
302                 // Is the call-back method there?
303                 if (!method_exists($this, $handlerName)) {
304                         // Please implement this
305                         throw new UnsupportedSocketErrorHandlerException(array($this, $handlerName, $errorCode), BaseConnectionHelper::EXCEPTION_UNSUPPORTED_ERROR_HANDLER);
306                 } // END - if
307
308                 // Return it
309                 return $handlerName;
310         }
311
312         /**
313          * Handles socket error for given socket resource and peer data. This method
314          * validates $socketResource if it is a valid resource (see is_resource())
315          * but assumes valid data in array $recipientData, except that
316          * count($recipientData) is always 2.
317          *
318          * @param       $method                         Value of __METHOD__ from calling method
319          * @param       $line                           Value of __LINE__ from calling method
320          * @param       $socketResource         A valid socket resource
321          * @param       $socketData                     A valid socket data array (0 = IP/file name, 1 = port)
322          * @return      void
323          * @throws      InvalidSocketException  If $socketResource is no socket resource
324          * @throws      NoSocketErrorDetectedException  If socket_last_error() gives zero back
325          */
326         protected final function handleSocketError ($method, $line, $socketResource, array $socketData) {
327                 // This method handles only socket resources
328                 if (!is_resource($socketResource)) {
329                         // No resource, abort here
330                         throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
331                 } // END - if
332
333                 // Check socket array, 1st element is mostly IP address (or file name), 2nd is port number
334                 //* DEBUG-DIE: */ die(__METHOD__ . ':socketData=' . print_r($socketData, TRUE));
335                 assert(isset($socketData[0]));
336                 assert(isset($socketData[1]));
337
338                 // Get error code for first validation (0 is not an error)
339                 $errorCode = socket_last_error($socketResource);
340
341                 // If the error code is zero, someone called this method without an error
342                 if ($errorCode == 0) {
343                         // No error detected (or previously cleared outside this method)
344                         throw new NoSocketErrorDetectedException(array($this, $socketResource), BaseListener::EXCEPTION_NO_SOCKET_ERROR);
345                 } // END - if
346
347                 // Get handler (method) name
348                 $handlerName = $this->getSocketErrorHandlerFromCode($errorCode);
349
350                 // Call-back the error handler method
351                 call_user_func_array(array($this, $handlerName), array($socketResource, $socketData));
352
353                 // Finally clear the error because it has been handled
354                 socket_clear_error($socketResource);
355         }
356
357         /**
358          * Translates socket error codes into our own internal names which can be
359          * used for call-backs.
360          *
361          * @param       $errorCode      The error code from socket_last_error() to be translated
362          * @return      $errorName      The translated name (all lower-case, with underlines)
363          */
364         public function translateSocketErrorCodeToName ($errorCode) {
365                 // Nothing bad happened by default
366                 $errorName = BaseRawDataHandler::SOCKET_CONNECTED;
367
368                 // Is the code a number, then we have to change it
369                 switch ($errorCode) {
370                         case 0: // Silently ignored, the socket is connected
371                                 break;
372
373                         case 11:  // "Resource temporary unavailable"
374                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_RESOURCE_UNAVAILABLE;
375                                 break;
376
377                         case 13:  // "Permission denied"
378                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_PERMISSION_DENIED;
379                                 break;
380
381                         case 32:  // "Broken pipe"
382                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_BROKEN_PIPE;
383                                 break;
384
385                         case 104: // "Connection reset by peer"
386                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_RESET_BY_PEER;
387                                 break;
388
389                         case 107: // "Transport end-point not connected"
390                         case 134: // On some (?) systems for 'transport end-point not connected'
391                                 // @TODO On some systems it is 134, on some 107?
392                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
393                                 break;
394
395                         case 110: // "Connection timed out"
396                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_TIMED_OUT;
397                                 break;
398
399                         case 111: // "Connection refused"
400                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED;
401                                 break;
402
403                         case 113: // "No route to host"
404                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_NO_ROUTE_TO_HOST;
405                                 break;
406
407                         case 114: // "Operation already in progress"
408                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_ALREADY_PROGRESS;
409                                 break;
410
411                         case 115: // "Operation now in progress"
412                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_OPERATION_IN_PROGRESS;
413                                 break;
414
415                         default: // Everything else <> 0
416                                 // Unhandled error code detected, so first debug it because we may want to handle it like the others
417                                 self::createDebugInstance(__CLASS__)->debugOutput('BASE-HUB[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode . ', MESSAGE = ' . socket_strerror($errorCode));
418
419                                 // Change it only in this class
420                                 $errorName = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
421                                 break;
422                 }
423
424                 // Return translated name
425                 return $errorName;
426         }
427
428         /**
429          * Shuts down a given socket resource. This method does only ease calling
430          * the right visitor.
431          *
432          * @param       $socketResource         A valid socket resource
433          * @return      void
434          */
435         public function shutdownSocket ($socketResource) {
436                 // Debug message
437                 self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
438
439                 // Set socket resource
440                 $this->setSocketResource($socketResource);
441
442                 // Get a visitor instance
443                 $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class');
444
445                 // Debug output
446                 self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
447
448                 // Call the visitor
449                 $this->accept($visitorInstance);
450         }
451
452         /**
453          * Half-shuts down a given socket resource. This method does only ease calling
454          * an other visitor than shutdownSocket() does.
455          *
456          * @param       $socketResource         A valid socket resource
457          * @return      void
458          */
459         public function halfShutdownSocket ($socketResource) {
460                 // Debug message
461                 self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM: Half-shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
462
463                 // Set socket resource
464                 $this->setSocketResource($socketResource);
465
466                 // Get a visitor instance
467                 $visitorInstance = ObjectFactory::createObjectByConfiguredName('half_shutdown_socket_visitor_class');
468
469                 // Debug output
470                 self::createDebugInstance(__CLASS__)->debugOutput('HUB-SYSTEM:' . $this->__toString() . ': visitorInstance=' . $visitorInstance->__toString());
471
472                 // Call the visitor
473                 $this->accept($visitorInstance);
474         }
475
476         // ************************************************************************
477         //                 Socket error handler call-back methods
478         // ************************************************************************
479
480         /**
481          * Handles socket error 'permission denied', but does not clear it for
482          * later debugging purposes.
483          *
484          * @param       $socketResource         A valid socket resource
485          * @param       $socketData                     A valid socket data array (0 = IP/file name, 1 = port)
486          * @return      void
487          * @throws      SocketBindingException  The socket could not be bind to
488          */
489         protected function socketErrorPermissionDeniedHandler ($socketResource, array $socketData) {
490                 // Get socket error code for verification
491                 $socketError = socket_last_error($socketResource);
492
493                 // Get error message
494                 $errorMessage = socket_strerror($socketError);
495
496                 // Shutdown this socket
497                 $this->shutdownSocket($socketResource);
498
499                 // Throw it again
500                 throw new SocketBindingException(array($this, $socketData, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
501         }
502
503         /**
504          * "Listens" for incoming network packages
505          *
506          * @param       $peerSuffix             Suffix for peer name (e.g. :0 for TCP(/UDP?) connections)
507          * @return      void
508          * @throws      InvalidSocketException  If an invalid socket resource has been found
509          */
510         protected function doListenSocketSelect ($peerSuffix) {
511                 // Check on all instances
512                 assert($this->getPoolInstance() instanceof Poolable);
513                 assert(is_resource($this->getSocketResource()));
514
515                 // Get all readers
516                 $readers = $this->getPoolInstance()->getAllSingleSockets();
517                 $writers = array();
518                 $excepts = array();
519
520                 // Check if we have some peers left
521                 $left = socket_select(
522                         $readers,
523                         $writers,
524                         $excepts,
525                         0,
526                         150
527                 );
528
529                 // Some new peers found?
530                 if ($left < 1) {
531                         // Debug message
532                         //* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: left=' . $left . ',serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
533
534                         // Nothing new found
535                         return;
536                 } // END - if
537
538                 // Debug message
539                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: serverSocket=' . $this->getSocketResource() . ',readers=' . print_r($readers, TRUE));
540
541                 // Do we have changed peers?
542                 if (in_array($this->getSocketResource(), $readers)) {
543                         /*
544                          * Then accept it, if this socket is set to non-blocking IO and the
545                          * connection is NOT sending any data, socket_read() may throw
546                          * error 11 (Resource temporary unavailable). This really nasty
547                          * because if you have blocking IO socket_read() will wait and wait
548                          * and wait ...
549                          */
550                         $newSocket = socket_accept($this->getSocketResource());
551
552                         // Debug message
553                         //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: newSocket=' . $newSocket . ',serverSocket=' .$this->getSocketResource());
554
555                         // Array for timeout settings
556                         $options  = array(
557                                 // Seconds
558                                 'sec'  => $this->getConfigInstance()->getConfigEntry('tcp_socket_accept_wait_sec'),
559                                 // Milliseconds
560                                 'usec' => $this->getConfigInstance()->getConfigEntry('tcp_socket_accept_wait_usec')
561                         );
562
563                         // Set timeout to configured seconds
564                         // @TODO Does this work on Windozer boxes???
565                         if (!socket_set_option($newSocket, SOL_SOCKET, SO_RCVTIMEO, $options)) {
566                                 // Handle this socket error with a faked recipientData array
567                                 $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
568                         } // END - if
569
570                         // Output result (only for debugging!)
571                         /*
572                         $option = socket_get_option($newSocket, SOL_SOCKET, SO_RCVTIMEO);
573                         self::createDebugInstance(__CLASS__)->debugOutput('SO_RCVTIMEO[' . gettype($option) . ']=' . print_r($option, TRUE));
574                         */
575
576                         // Enable SO_OOBINLINE
577                         if (!socket_set_option($newSocket, SOL_SOCKET, SO_OOBINLINE ,1)) {
578                                 // Handle this socket error with a faked recipientData array
579                                 $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
580                         } // END - if
581
582                         // Set non-blocking
583                         if (!socket_set_nonblock($newSocket)) {
584                                 // Handle this socket error with a faked recipientData array
585                                 $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
586                         } // END - if
587
588                         // Add it to the peers
589                         $this->getPoolInstance()->addPeer($newSocket, BaseConnectionHelper::CONNECTION_TYPE_INCOMING);
590
591                         // Get peer name
592                         if (!socket_getpeername($newSocket, $peerName)) {
593                                 // Handle this socket error with a faked recipientData array
594                                 $this->handleSocketError(__METHOD__, __LINE__, $newSocket, array('0.0.0.0', '0'));
595                         } // END - if
596
597                         // Get node instance
598                         $nodeInstance = NodeObjectFactory::createNodeInstance();
599
600                         // Create a faked package data array
601                         $packageData = array(
602                                 NetworkPackage::PACKAGE_DATA_SENDER    => $peerName . $peerSuffix,
603                                 NetworkPackage::PACKAGE_DATA_RECIPIENT => $nodeInstance->getSessionId(),
604                                 NetworkPackage::PACKAGE_DATA_STATUS    => NetworkPackage::PACKAGE_STATUS_FAKED
605                         );
606
607                         // Get a connection info instance
608                         $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), 'listener');
609
610                         // Will the info instance with listener data
611                         $infoInstance->fillWithListenerInformation($this);
612
613                         // Get a socket registry
614                         $registryInstance = SocketRegistryFactory::createSocketRegistryInstance();
615
616                         // Register the socket with the registry and with the faked array
617                         $registryInstance->registerSocket($infoInstance, $newSocket, $packageData);
618                 } // END - if
619
620                 // Do we have to rewind?
621                 if (!$this->getIteratorInstance()->valid()) {
622                         // Rewind the list
623                         $this->getIteratorInstance()->rewind();
624                 } // END - if
625
626                 // Get the current value
627                 $currentSocket = $this->getIteratorInstance()->current();
628
629                 // Handle it here, if not main server socket
630                 //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TCP-LISTENER[' . __METHOD__ . ':' . __LINE__ . ']: currentSocket=' . $currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] . ',type=' . $currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] . ',serverSocket=' . $this->getSocketResource());
631                 if (($currentSocket[BasePool::SOCKET_ARRAY_CONN_TYPE] != BaseConnectionHelper::CONNECTION_TYPE_SERVER) && ($currentSocket[BasePool::SOCKET_ARRAY_RESOURCE] != $this->getSocketResource())) {
632                         // ... or else it will raise warnings like 'Transport endpoint is not connected'
633                         $this->getHandlerInstance()->processRawDataFromResource($currentSocket);
634                 } // END - if
635
636                 // Advance to next entry. This should be the last line.
637                 $this->getIteratorInstance()->next();
638         }
639 }
640
641 // [EOF]
642 ?>