Completed
Push — closes-181 ( 070992...8d3649 )
by Victor
06:30
created

Socket::initScanner()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 16
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 0
crap 12
1
<?php
2
/**
3
 * Copyright (c) 2017 Viktar Dubiniuk <[email protected]>
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
10
namespace OCA\Files_Antivirus\Scanner;
11
12
use OCA\Files_Antivirus\AppConfig;
13
use OCP\ILogger;
14
15
class Socket extends Daemon {
16
17 1
	public function __construct(AppConfig $config, ILogger $logger) {
18 1
		parent::__construct($config, $logger);
19
	}
20
21
	public function initScanner(){
22
		parent::initScanner();
23
		$this->writeHandle = stream_socket_client(
24
			'unix://' . $this->appConfig->getAvSocket(), $errorCode, $errorMessage, 5
25
		);
26
		if (!$this->getWriteHandle()) {
27
			throw new InitException(
28
				sprintf(
29
					'Could not connect to socket "%s": %s (code %d)',
30
					$this->appConfig->getAvSocket(),
31
					$errorMessage,
32
					$errorCode
33
				)
34
			);
35
		}
36
37
		if (@fwrite($this->getWriteHandle(), "nINSTREAM\n") === false) {
38
			throw new InitException(
39
				sprintf(
40
					'Writing to socket "%s" failed',
41
					$this->appConfig->getAvSocket()
42
				)
43
			);
44
		}
45
	}
46
}
47