| | 161 | } |
|---|
| | 162 | |
|---|
| | 163 | /** |
|---|
| | 164 | * sets an option |
|---|
| | 165 | * |
|---|
| | 166 | * @param int $level protocol level of option |
|---|
| | 167 | * @param int $name option name |
|---|
| | 168 | * @param mixed $value option value |
|---|
| | 169 | * @throws stubConnectionException |
|---|
| | 170 | */ |
|---|
| | 171 | public function setOption($level, $name, $value) |
|---|
| | 172 | { |
|---|
| | 173 | if (isset($this->options[$level]) === false) { |
|---|
| | 174 | $this->options[$level] = array(); |
|---|
| | 175 | } |
|---|
| | 176 | |
|---|
| | 177 | $this->options[$level][$name] = $value; |
|---|
| | 178 | if ($this->isConnected() === true) { |
|---|
| | 179 | if (socket_set_option($this->fp, $level, $name, $value) === false) { |
|---|
| | 180 | throw new stubConnectionException('Failed to set option ' . $name . ' on level ' . $level . ' to value ' . $value); |
|---|
| | 181 | } |
|---|
| | 182 | } |
|---|
| | 183 | } |
|---|
| | 184 | |
|---|
| | 185 | /** |
|---|
| | 186 | * returns an option |
|---|
| | 187 | * |
|---|
| | 188 | * @param int $level protocol level of option |
|---|
| | 189 | * @param int $name option name |
|---|
| | 190 | * @return mixed |
|---|
| | 191 | * @throws stubConnectionException |
|---|
| | 192 | */ |
|---|
| | 193 | public function getOption($level, $name) |
|---|
| | 194 | { |
|---|
| | 195 | if ($this->isConnected() === true) { |
|---|
| | 196 | $option = socket_get_option($this->fp, $level, $name); |
|---|
| | 197 | if (false === $option) { |
|---|
| | 198 | throw new stubConnectionException('Failed to retrieve option ' . $name . ' on level ' . $level); |
|---|
| | 199 | } |
|---|
| | 200 | |
|---|
| | 201 | if (isset($this->options[$level]) === false) { |
|---|
| | 202 | $this->options[$level] = array(); |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | $this->options[$level][$name] = $option; |
|---|
| | 206 | } |
|---|
| | 207 | |
|---|
| | 208 | if (isset($this->options[$level]) === true && isset($this->options[$level][$name]) === true) { |
|---|
| | 209 | return $this->options[$level][$name]; |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | return null; |
|---|