- moved 'pool' interfaces to 'core' as they are generic enough.
- more rewrites (broken stuff)
Signed-off-by: Roland Häder <roland@mxchange.org>
$lastError = socket_last_error($socketResource);
// Doesn't work!
- throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
// Debug message
const CHUNK_SPLITS_INDEX_SERIAL = 1;
const CHUNK_SPLITS_INDEX_RAW_DATA = 2;
+ // Exception codes
+ const EXCEPTION_FINAL_CHUNK_VERIFICATION = 0xf3300;
+
/**
* The final array for assembling the original package back together
*/
$this->isValidFinalChunk($chunks);
} catch (AssertionException $e) {
// Last chunk is not valid
- throw new FinalChunkVerificationException(array($this, $chunks, $e), BaseListener::EXCEPTION_FINAL_CHUNK_VERIFICATION);
+ throw new FinalChunkVerificationException(array($this, $chunks, $e), self::EXCEPTION_FINAL_CHUNK_VERIFICATION);
}
// Do we have some pending chunks (no final)?
// And throw again
// @TODO Move this to the socket error handler
- throw new SocketOptionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketOptionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
/*
$helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
// And throw again
- throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketOptionException(array($helperInstance, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
// Last step: mark connection as initialized
$this->shutdownSocket($socketResource);
// Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
}
/**
$this->shutdownSocket($socketResource);
// Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
}
/**
$this->shutdownSocket($socketResource);
// Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
}
/**
$this->shutdownSocket($socketResource);
// Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
}
/**
$this->halfShutdownSocket($socketResource);
// Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
}
/**
$this->shutdownSocket($socketResource);
// Throw it again
- throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketConnectionException(array($this, $socketResource, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
}
/**
* possible here because that method would throw an
* InvalidSocketException back.
*/
- throw new SocketCreationException(array($helperInstance, gettype($socketResource)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
+ throw new SocketCreationException(array($helperInstance, gettype($socketResource)), SocketHandler::EXCEPTION_SOCKET_CREATION_FAILED);
} // END - if
// Get socket error code for verification
$helperInstance->handleSocketError(__METHOD__, __LINE__, $socketResource, array('0.0.0.0', '0'));
// Then throw again
- throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
+ throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), SocketHandler::EXCEPTION_SOCKET_CREATION_FAILED);
} // END - if
// Debug message
// Could not shutdown socket, this is fine if e.g. the other side is not connected, so analyse it
if (socket_last_error($this->getSocketResource()) != 107) {
// Something bad happened while we shutdown a socket
- throw new SocketShutdownException($this, BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new SocketShutdownException($this, SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
} // END - if
// Is the socket resource valid?
if (!is_resource($mainSocket)) {
// Something bad happened
- throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
// Get socket error code for verification
$this->handleSocketError(__METHOD__, __LINE__, $mainSocket, array('0.0.0.0', '0'));
/*
// Then throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, socket_strerror($socketError)), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
// Is the socket a valid resource or do we have any error?
if (!is_resource($mainSocket)) {
// Then throw an InvalidSocketException
- throw new InvalidSocketException(array($this, $mainSocket), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
/*
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
$this->shutdownSocket($mainSocket);
// And throw again
- throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $mainSocket, $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
*/
const STACKER_NAME_MULTIPLE_MESSAGE = 'multiple_message';
+ // Exception codes
+ const EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER = 0xf2200;
+
/**
* Pending data
*/
// Abort if the call-back method is not there
if (!method_exists($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]])) {
// Throw an exception
- throw new UnsupportedPackageCodeHandlerException(array($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]], $packageContent), BaseListener::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
+ throw new UnsupportedPackageCodeHandlerException(array($this, $this->callbacks[$packageContent[BaseRawDataHandler::PACKAGE_ERROR_CODE]], $packageContent), self::EXCEPTION_UNSUPPORTED_PACKAGE_CODE_HANDLER);
} // END - if
// Call it back
const PROTOCOL_TCP = 'TCP';
const PROTOCOL_UDP = 'UDP';
+ /**************************************************************************
+ * Exception codes *
+ **************************************************************************/
+ const EXCEPTION_UNEXPECTED_PACKAGE_STATUS = 0xff00;
+ const EXCEPTION_INVALID_DATA_CHECKSUM = 0xff01;
+
/**
* Protected constructor
*
$this->handleSocketError(__METHOD__, __LINE__, $encodedDataArray[self::RAW_SOCKET_INDEX], array('0.0.0.0', '0'));
// And throw it
- throw new InvalidSocketException(array($this, $encodedDataArray[self::RAW_SOCKET_INDEX], $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $encodedDataArray[self::RAW_SOCKET_INDEX], $socketError, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
} elseif (($sentBytes === 0) && (strlen($encodedDataArray[self::RAW_ENCODED_DATA_INDEX]) > 0)) {
// Nothing sent means we are done
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: All sent! (LINE=' . __LINE__ . ')');
// Is the package status 'failed'?
if ($packageData[self::PACKAGE_DATA_STATUS] != self::PACKAGE_STATUS_FAILED) {
// Not failed!
- throw new UnexpectedPackageStatusException(array($this, $packageData, self::PACKAGE_STATUS_FAILED), BaseListener::EXCEPTION_UNEXPECTED_PACKAGE_STATUS);
+ throw new UnexpectedPackageStatusException(array($this, $packageData, self::PACKAGE_STATUS_FAILED), self::EXCEPTION_UNEXPECTED_PACKAGE_STATUS);
} // END - if
// Remove this entry
// Is the checksum valid?
if (!$this->isChecksumValid($decodedContent, $decodedData)) {
// Is not the same, so throw an exception here
- throw new InvalidDataChecksumException(array($this, $decodedContent, $decodedData), BaseListener::EXCEPTION_INVALID_DATA_CHECKSUM);
+ throw new InvalidDataChecksumException(array($this, $decodedContent, $decodedData), self::EXCEPTION_INVALID_DATA_CHECKSUM);
} // END - if
/*
// Is it a valid resource?
if (!is_resource($socketResource)) {
// Throw an exception
- throw new InvalidSocketException(array($this, $socketResource), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $socketResource), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
// Get error code
$this->getListenerInstance()->shutdownSocket($socketResource);
// And throw again
- throw new InvalidSocketException(array($this, $socketResource, $errorCode, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $socketResource, $errorCode, $errorMessage), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
}
$lastError = socket_last_error($socketResource);
// Doesn't work!
- throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), SocketHandler::EXCEPTION_INVALID_SOCKET);
*/
} // END - if
} else {
// Still no socket resource?
if (!is_resource($socketResource)) {
// Then abort here with an exception (may happen after socket_shutdown())
- throw new InvalidSocketException(array($helperInstance, $socketResource, 'unknown', 'unknown'), BaseListener::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($helperInstance, $socketResource, 'unknown', 'unknown'), SocketHandler::EXCEPTION_INVALID_SOCKET);
} // END - if
} // END - if
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An interface for pools
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface Poolable extends FrameworkInterface {
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * An interface for pools
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface PoolableListener extends Poolable {
- /**
- * Adds a listener instance to this pool
- *
- * @param $listenerInstance An instance of a Listenable class
- * @return void
- */
- function addListener (Listenable $listenerInstance);
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-/**
- * A default peer pool class
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface PoolablePeer extends Poolable, SocketTag {
- /**
- * Adds a socket resource to the peer pool
- *
- * @param $socketResource A valid (must be!) socket resource
- * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
- * @return void
- * @throws InvalidSocketException If the given resource is invalid or errorous
- * @throws InvalidConnectionTypeException If the provided connection type is not valid
- */
- function addPeer ($socketResource, $connectionType);
-
- /**
- * Getter for array of all socket resource arrays
- *
- * @return $sockets An array with all socket arrays
- */
- function getAllSockets ();
-
- /**
- * Getter for array of all socket resources
- *
- * @return $sockets An array with all sockets
- */
- function getAllSingleSockets ();
-
- /**
- * "Getter" for all sockets of specified type
- *
- * @param $connectionType Type of connection, can only be 'incoming', 'outgoing' or 'server'
- * @return $sockets An array with sockets of given type
- * @throws InvalidConnectionTypeException If the provided connection type is not valid
- */
- function getSocketsByConnectionType ($connectionType);
-}
-
-// [EOF]
-?>