3 * A general listener class
5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
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.
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.
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/>.
24 class BaseListener extends BaseHubSystem {
25 // Exception code constants
26 const EXCEPTION_INVALID_SOCKET = 0xa00;
29 * Used protocol (Default: invalid, which is indeed invalid...)
31 private $protcol = 'invalid';
34 * Address (IP mostly) we shall listen on
36 private $listenAddress = '0.0.0.0'; // This is the default and listens on all interfaces
39 * Port we shall listen on (or wait for incoming data)
41 private $listenPort = 0; // This port MUST be changed by your application
44 * Wether we are in blocking or non-blocking mode (default: non-blocking
46 private $blockingMode = false;
51 private $socketResource = null;
54 * Protected constructor
56 * @param $className Name of the class
59 protected function __construct ($className) {
60 // Call parent constructor
61 parent::__construct($className);
65 * Setter for listen address
67 * @param $listenAddress The address this listener should listen on
70 protected final function setListenAddress ($listenAddress) {
71 $this->listenAddress = (string) $listenAddress;
75 * Getter for listen address
77 * @return $listenAddress The address this listener should listen on
79 public final function getListenAddress () {
80 return $this->listenAddress;
84 * Setter for listen port
86 * @param $listenPort The port this listener should listen on
89 protected final function setListenPort ($listenPort) {
90 $this->listenPort = (int) $listenPort;
94 * Getter for listen port
96 * @return $listenPort The port this listener should listen on
98 public final function getListenPort () {
99 return $this->listenPort;
103 * "Setter" to set listen address from configuration entry
105 * @param $configEntry The configuration entry holding our listen address
108 public final function setListenAddressByConfiguration ($configEntry) {
109 $this->setListenAddress($this->getConfigInstance()->readConfig($configEntry));
113 * "Setter" to set listen port from configuration entry
115 * @param $configEntry The configuration entry holding our listen port
118 public final function setListenPortByConfiguration ($configEntry) {
119 $this->setListenPort($this->getConfigInstance()->readConfig($configEntry));
123 * Setter for protocol
125 * @param $protocol Used protocol
128 protected final function setProtocol ($protocol) {
129 $this->protocol = (string) $protocol;
133 * Getter for protocol
135 * @return $protocol Used protocol
137 public final function getProtocol () {
138 return $this->protocol;
142 * Setter for blocking-mode
144 * @param $blockingMode Wether blocking-mode is disabled (default) or enabled
147 protected final function setBlockingMode ($blockingMode) {
148 $this->blockingMode = (boolean) $blockingMode;
152 * Checks wether blocking-mode is enabled or disabled
154 * @return $blockingMode Wether blocking mode is disabled or enabled
156 public final function isBlockingModeEnabled () {
157 return $this->blockingMode;
161 * Setter for socket resource
163 * @param $socketResource The socket resource we shall set
166 protected final function setSocketResource ($socketResource) {
167 $this->setSocketResource = $setSocketResource;
171 * Getter for socket resource
173 * @return $socketResource The socket resource we shall set
175 protected final function getSocketResource () {
176 return $this->setSocketResource;