|
25 | 25 | */ |
26 | 26 | use PEAR2\Net\Transmitter as T; |
27 | 27 |
|
| 28 | +/** |
| 29 | + * Uses shared memory to keep responses in when using persistent connections. |
| 30 | + */ |
| 31 | +use PEAR2\Cache\SHM; |
| 32 | + |
28 | 33 | /** |
29 | 34 | * A RouterOS client. |
30 | 35 | * |
@@ -75,6 +80,12 @@ class Client |
75 | 80 | * Key is the tag of the request, and the value is the callback for it. |
76 | 81 | */ |
77 | 82 | protected $callbacks = array(); |
| 83 | + |
| 84 | + /** |
| 85 | + * @var SHM Handler for shared response buffer. Remains NULL when the |
| 86 | + * connection is not a persistent one. |
| 87 | + */ |
| 88 | + protected $shmHandler = null; |
78 | 89 |
|
79 | 90 | /** |
80 | 91 | * @var bool Whether to stream future responses. |
@@ -115,6 +126,13 @@ public function __construct($host, $username, $password = '', $port = 8728, |
115 | 126 | ); |
116 | 127 | } |
117 | 128 | } |
| 129 | + |
| 130 | + if ($persist) { |
| 131 | + $this->shmHandler = new SHM( |
| 132 | + 'PEAR2\Net\RouterOS\Client tcp://' . |
| 133 | + "{$host}:{$port}/{$username}" |
| 134 | + ); |
| 135 | + } |
118 | 136 | } |
119 | 137 |
|
120 | 138 | /** |
@@ -185,7 +203,20 @@ public static function login(Communicator $com, $username, $password = '') |
185 | 203 | ) : $e; |
186 | 204 | } |
187 | 205 | } |
188 | | - |
| 206 | + |
| 207 | + /** |
| 208 | + * Login to a RouterOS connection. |
| 209 | + * |
| 210 | + * This is the actual login procedure, applied regardless of persistence and |
| 211 | + * charset settings. |
| 212 | + * |
| 213 | + * @param Communicator $com The communicator to attempt to login to. |
| 214 | + * @param string $username The RouterOS username. |
| 215 | + * @param string $password The RouterOS password. Potentially parsed |
| 216 | + * already by iconv. |
| 217 | + * |
| 218 | + * @return bool TRUE on success, FALSE on failure. |
| 219 | + */ |
189 | 220 | private static function _performLogin( |
190 | 221 | Communicator $com, $username, $password |
191 | 222 | ) { |
|
0 commit comments