From 1eff6a8fe74aeb68b2780b43a48233fec0e3a897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=9A=84=E5=A6=82=E6=9E=9C?= Date: Fri, 11 Dec 2020 12:18:34 +0800 Subject: [PATCH] =?UTF-8?q?linger=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Process/Socket/AbstractTcpProcess.php | 1 + src/Process/Socket/AbstractUnixProcess.php | 1 + src/Process/Socket/TcpProcessConfig.php | 17 +++++++++++++++++ src/Process/Socket/UnixProcessConfig.php | 17 +++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/Process/Socket/AbstractTcpProcess.php b/src/Process/Socket/AbstractTcpProcess.php index 998e9a5..857df20 100644 --- a/src/Process/Socket/AbstractTcpProcess.php +++ b/src/Process/Socket/AbstractTcpProcess.php @@ -25,6 +25,7 @@ public function run($arg) $socket = new Socket(AF_INET,SOCK_STREAM,0); $socket->setOption(SOL_SOCKET,SO_REUSEPORT,true); $socket->setOption(SOL_SOCKET,SO_REUSEADDR,true); + $socket->setOption(SOL_SOCKET,SO_LINGER,$this->getConfig()->getLinger()); $ret = $socket->bind($this->getConfig()->getListenAddress(),$this->getConfig()->getListenPort()); if(!$ret){ throw new Exception(static::class." bind {$this->getConfig()->getListenAddress()}:{$this->getConfig()->getListenPort()} fail case ".$socket->errMsg); diff --git a/src/Process/Socket/AbstractUnixProcess.php b/src/Process/Socket/AbstractUnixProcess.php index f43853f..b274041 100644 --- a/src/Process/Socket/AbstractUnixProcess.php +++ b/src/Process/Socket/AbstractUnixProcess.php @@ -27,6 +27,7 @@ public function run($arg) unlink($this->getConfig()->getSocketFile()); } $socketServer = new Socket(AF_UNIX,SOCK_STREAM,0); + $socketServer->setOption(SOL_SOCKET,SO_LINGER,$this->getConfig()->getLinger()); if(!$socketServer->bind($this->getConfig()->getSocketFile())){ throw new Exception(static::class.' bind '.$this->getConfig()->getSocketFile(). ' fail case '.$socketServer->errMsg); } diff --git a/src/Process/Socket/TcpProcessConfig.php b/src/Process/Socket/TcpProcessConfig.php index 53a47e0..a3e0700 100644 --- a/src/Process/Socket/TcpProcessConfig.php +++ b/src/Process/Socket/TcpProcessConfig.php @@ -11,6 +11,23 @@ class TcpProcessConfig extends Config protected $listenAddress = '0.0.0.0'; protected $listenPort; protected $asyncCallback = true; + protected $linger = [ 'l_linger' => 0, 'l_onoff' => 0]; + + /** + * @return int[] + */ + public function getLinger(): array + { + return $this->linger; + } + + /** + * @param int[] $linger + */ + public function setLinger(array $linger): void + { + $this->linger = $linger; + } /** * @return string diff --git a/src/Process/Socket/UnixProcessConfig.php b/src/Process/Socket/UnixProcessConfig.php index 85514ca..10cf849 100644 --- a/src/Process/Socket/UnixProcessConfig.php +++ b/src/Process/Socket/UnixProcessConfig.php @@ -10,6 +10,23 @@ class UnixProcessConfig extends Config { protected $socketFile; protected $asyncCallback = true; + protected $linger = [ 'l_linger' => 0, 'l_onoff' => 0]; + + /** + * @return int[] + */ + public function getLinger(): array + { + return $this->linger; + } + + /** + * @param int[] $linger + */ + public function setLinger(array $linger): void + { + $this->linger = $linger; + } /** * @return mixed