Skip to content

Commit

Permalink
feat: make socket connect timeout configurable. (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: ProtossChrisTW <chris.lee@getoken.io>
Co-authored-by: Krishnaprasad MG <sunspikes@gmail.com>
  • Loading branch information
3 people committed Mar 14, 2022
1 parent bd1a7a8 commit 218602d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config/clamav.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
*/
'tcp_socket' => env('CLAMAV_TCP_SOCKET', 'tcp://127.0.0.1:3310'),

/*
|--------------------------------------------------------------------------
| Socket connect timeout
|--------------------------------------------------------------------------
| This option defines the maximum time to wait in seconds for socket connection attempts before failure or timeout, default null = no limit.
*/
'socket_connect_timeout' => env('CLAMAV_SOCKET_CONNECT_TIMEOUT', null),

/*
|--------------------------------------------------------------------------
| Socket read timeout
Expand Down
2 changes: 1 addition & 1 deletion src/ClamavValidator/ClamavValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected function getFilePath($file): string
protected function createQuahogScannerClient(string $socket): QuahogClient
{
// Create a new client socket instance
$client = (new SocketFactory())->createClient($socket);
$client = (new SocketFactory())->createClient($socket, Config::get('clamav.socket_connect_timeout'));

return new QuahogClient($client, Config::get('clamav.socket_read_timeout'), PHP_NORMAL_READ);
}
Expand Down
1 change: 1 addition & 0 deletions tests/ClamavValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private function setConfig(array $opts = []): void
$config->shouldReceive('get')->with('clamav.unix_socket')->andReturn(!$opts['error'] ? '/var/run/clamav/clamd.ctl' : '/dev/null');
$config->shouldReceive('get')->with('clamav.tcp_socket')->andReturn(!$opts['error'] ? 'tcp://127.0.0.1:3310' : 'tcp://127.0.0.1:0');
$config->shouldReceive('get')->with('clamav.socket_read_timeout')->andReturn(30);
$config->shouldReceive('get')->with('clamav.socket_connect_timeout')->andReturn(5);
$config->shouldReceive('get')->with('clamav.skip_validation')->andReturn($opts['skip']);

Config::swap($config);
Expand Down

0 comments on commit 218602d

Please sign in to comment.