Skip to content

Commit

Permalink
linger优化
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Dec 11, 2020
1 parent e3016fa commit 1eff6a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Process/Socket/AbstractTcpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/Process/Socket/AbstractUnixProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 17 additions & 0 deletions src/Process/Socket/TcpProcessConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/Process/Socket/UnixProcessConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1eff6a8

Please sign in to comment.