Completed
Pull Request — master (#195)
by Victor
16:47 queued 06:49
created

Socket::initScanner()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
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
	public function __construct(AppConfig $config, ILogger $logger) {
18
		parent::__construct($config, $logger);
19
		$this->writeHandle = stream_socket_client(
20
			'unix://' . $this->appConfig->getAvSocket(), $errorCode, $errorMessage, 5
21
		);
22
		if (!$this->getWriteHandle()) {
23
			throw new InitException(
24
				sprintf(
25
					'Could not connect to socket "%s": %s (code %d)',
26
					$this->appConfig->getAvSocket(),
27
					$errorMessage,
28
					$errorCode
29
				)
30
			);
31
		}
32
	}
33
34
	public function initScanner(){
35
		parent::initScanner();
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