Skip to content

Commit 12ea824

Browse files
committed
Made the query sending and login persistence aware.
1 parent 77cf445 commit 12ea824

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/PEAR2/Net/RouterOS/Client.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
*/
2626
use PEAR2\Net\Transmitter as T;
2727

28+
/**
29+
* Uses shared memory to keep responses in when using persistent connections.
30+
*/
31+
use PEAR2\Cache\SHM;
32+
2833
/**
2934
* A RouterOS client.
3035
*
@@ -75,6 +80,12 @@ class Client
7580
* Key is the tag of the request, and the value is the callback for it.
7681
*/
7782
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;
7889

7990
/**
8091
* @var bool Whether to stream future responses.
@@ -115,6 +126,13 @@ public function __construct($host, $username, $password = '', $port = 8728,
115126
);
116127
}
117128
}
129+
130+
if ($persist) {
131+
$this->shmHandler = new SHM(
132+
'PEAR2\Net\RouterOS\Client tcp://' .
133+
"{$host}:{$port}/{$username}"
134+
);
135+
}
118136
}
119137

120138
/**
@@ -185,7 +203,20 @@ public static function login(Communicator $com, $username, $password = '')
185203
) : $e;
186204
}
187205
}
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+
*/
189220
private static function _performLogin(
190221
Communicator $com, $username, $password
191222
) {

src/PEAR2/Net/RouterOS/Query.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,17 @@ public function send(Communicator $com)
182182
}
183183
return $this->_send($com);
184184
}
185-
185+
186+
/**
187+
* Sends the query over a communicator.
188+
*
189+
* The only difference with the non private equivalent is that this one does
190+
* not do locking.
191+
*
192+
* @param Communicator $com The communicator to send the query over.
193+
*
194+
* @return int The number of bytes sent.
195+
*/
186196
private function _send(Communicator $com)
187197
{
188198
if (!$com->getTransmitter()->isAcceptingData()) {

0 commit comments

Comments
 (0)