...
|
...
|
@@ -36,7 +36,7 @@ class ProxyService |
|
|
SWOOLE_SOCK_TCP//|SWOOLE_SSL
|
|
|
);
|
|
|
$server->set([
|
|
|
'dispatch_mode' => 2 // 固定模式
|
|
|
'dispatch_mode' => 2 // 固定模式
|
|
|
]);
|
|
|
//监听连接进入事件。
|
|
|
$server->on('Connect', function ($server, $fd) {
|
...
|
...
|
@@ -51,18 +51,20 @@ class ProxyService |
|
|
if(empty($this->clients[$fd])){
|
|
|
$this->clients[$fd] = new SmtpClient();
|
|
|
}
|
|
|
|
|
|
$client = $this->clients[$fd];
|
|
|
// 加锁
|
|
|
$this->clients[$fd]->lock();
|
|
|
$client->lock();
|
|
|
// 处理数据
|
|
|
$result = $this->clients[$fd]->exec($data);
|
|
|
$result = $client->exec($data);
|
|
|
// 解锁
|
|
|
$this->clients[$fd]->unlock();
|
|
|
$client->unlock();
|
|
|
// 返回结果
|
|
|
$server->send($fd, $this->push($result[1]));
|
|
|
// 是否关闭连接
|
|
|
if($result[0]===false){
|
|
|
// 关闭并释放资源
|
|
|
$this->clients[$fd]->close();
|
|
|
$client->close();
|
|
|
$this->clients[$fd] = null;
|
|
|
unset($this->clients[$fd]);
|
|
|
|
...
|
...
|
@@ -73,6 +75,7 @@ class ProxyService |
|
|
//监听连接关闭事件。
|
|
|
$server->on('Close', function ($server, $fd) {
|
|
|
echo '连接关闭了 => '.$fd."\n";
|
|
|
$this->clients[$fd] = null;
|
|
|
unset($this->clients[$fd]);
|
|
|
});
|
|
|
|
...
|
...
|
|