// Trace message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol));
- // Set protocol
+ // Set all values
$socketInstance->setSocketProtocol($socketProtocol);
-
- // Set content/hash to null
- $packageInstance->setPackageContent(NULL);
- $packageInstance->setContentHash(NULL);
-
- // Set the resource ...
$socketInstance->setSocketResource($socketResource);
-
- // ... and package instance
$socketInstance->setPackageDataInstance($packageInstance);
// Return the prepared instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: socketInstance=%s - EXIT!', strtoupper($socketProtocol), $socketInstance->__toString()));
return $socketInstance;
}
* @return void
*/
public function accept (Visitor $visitorInstance) {
- // Debug message
- /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
-
// Visit this listener
+ /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - CALLED!');
$visitorInstance->visitSocket($this);
- // Debug message
+ // Trace message
/* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: ' . $visitorInstance->__toString() . ' has visited ' . $this->__toString() . ' - EXIT!');
}
* @throws InvalidSocketException If socket is invalid
*/
public function getSocketPeerName (&$peerAddress, &$peerPort) {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress=%s,peerPort=%d - CALLED!', strtoupper($this->getSocketProtocol()), $peerAddress, $peerPort));
-
// Should be valid socket
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress[%s]=%s,peerPort[%s]=%d - CALLED!', strtoupper($this->getSocketProtocol()), gettype($peerAddress), $peerAddress, gettype($peerPort), $peerPort));
if (!$this->isValidSocket()) {
// Throw exception
throw new InvalidSocketException(array($this), self::EXCEPTION_INVALID_SOCKET);
* http://de2.php.net/manual/en/function.socket-getpeername.php#35656
*/
if ($this->getSocketProtocol() == StorableSocket::SOCKET_PROTOCOL_UDP) {
- // UDP is WIP:
+ // UDP is work-in-progress:
$this->partialStub('UDP sockets are unfinished.');
} else {
// Use socket_getpeername()
$result = socket_getpeername($this->getSocketResource(), $peerAddress, $peerPort);
}
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress=%s,peerPort=%d,result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), $peerAddress, $peerPort, gettype($result), intval($result)));
-
// Return result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: peerAddress=%s,peerPort=%d,result[%s]=%d - EXIT!', strtoupper($this->getSocketProtocol()), $peerAddress, $peerPort, gettype($result), intval($result)));
return $result;
}
// Make sure all parameters are valid
if (($connectionType != StorableSocket::CONNECTION_TYPE_INCOMING) && ($connectionType != StorableSocket::CONNECTION_TYPE_OUTGOING)) {
// Abort here
- throw new InvalidArgumentException(sprintf('connectionType=%s is whether "%s" nor "%s".', $connectionType, StorableSocket::CONNECTION_TYPE_INCOMING, StorableSocket::CONNECTION_TYPE_OUTGOING));
+ throw new InvalidArgumentException(sprintf('connectionType=%s is whether "%s" nor "%s".',
+ $connectionType,
+ StorableSocket::CONNECTION_TYPE_INCOMING,
+ StorableSocket::CONNECTION_TYPE_OUTGOING
+ ));
} // END - if
// Determine protocol instance
// Get the helper instance from registry
$helperInstance = GenericRegistry::getRegistry()->getInstance('connection');
- // Possibly noisy debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...');
-
- // Resolve the peer's state (but ignore return value)
- PeerStateResolver::resolveStateByPackage($helperInstance, $packageInstance, $socketInstance);
+ // Is a state set and it's name is other than socket's error code?
+ if ($helperInstance->getStateInstance() instanceof PeerStateable && $helperInstance->getPrintableState() !== $socketInstance->translateLastSocketErrorCodeToName()) {
+ // Resolve the peer's state (but ignore return value)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...');
+ PeerStateResolver::resolveStateByPackage($helperInstance, $packageInstance, $socketInstance);
+ }
} catch (InvalidSocketException $e) {
// This cannot be fixed, so log it away
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageInstance->getRecipientUnl() . ': ' . $e->getMessage());
}
// And return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: socketInstance=%s - EXIT!', $socketInstance->__toString()));
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: socketResource=' . $socketInstance->getSocketResource() . ',packageInstance=' . print_r($packageInstance, TRUE));
return $socketInstance;
}
*/
public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance, $errorCode) {
// Error code and helper's state name should not be the same
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: helperInstance=%s,packageInstance=%s,socketInstance=%s,errorCode=%s - CALLED!', $helperInstance->__toString(), $packageInstance->__toString(), $socketInstance->__to_string(), $errorCode));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: helperInstance=%s,packageInstance=%s,socketInstance=%s,errorCode=%s - CALLED!', $helperInstance->__toString(), $packageInstance->__toString(), $socketInstance->__toString(), $errorCode));
if ($errorCode == $helperInstance->getPrintableState()) {
// Not valid!
throw new InvalidArgumentException(sprintf('Current state and errorCode=%s are the same.', $errorCode));
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageInstance An instance of a DeliverablePackage class
* @param $socketInstance An instance of a StorableSocket class
- * @return $stateInstance An instance of the resolved state
+ * @return $stateInstance An instance of a PeerStateable class
* @throws InvalidSocketException If socketResource, even from getSocketResource() is no valid resource
* @todo ~30% done
*/
} // END - if
// Translate the error code to an own name
- $errorName = $socketInstance->translateLastSocketErrorCodeToName();
+ $errorCode = $socketInstance->translateLastSocketErrorCodeToName();
// Create a state instance based on $errorCode. This factory does the hard work for us
- $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageInstance, $socketInstance, $errorName);
+ $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageInstance, $socketInstance, $errorCode);
// Return the prepared instance
return $stateInstance;
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageInstance An instance of a DeliverablePackage class
* @param $socketInstance An instance of a StorableSocket class
- * @return $stateInstance An instance of the resolved state
+ * @return $stateInstance An instance of a PeerStateable class
*/
static function resolveStateByPackage (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance);