aboutsummaryrefslogtreecommitdiff
path: root/daemon/ExternalSource.cpp
blob: fe5824b04812eb822738734695b79f731d1c2b72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * Copyright (C) ARM Limited 2010-2014. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include "ExternalSource.h"

#include <sys/prctl.h>

#include "Logging.h"
#include "OlySocket.h"
#include "SessionData.h"

ExternalSource::ExternalSource(sem_t *senderSem) : mBuffer(0, FRAME_EXTERNAL, 1024, senderSem), mSock("/tmp/gator") {
}

ExternalSource::~ExternalSource() {
}

bool ExternalSource::prepare() {
	return true;
}

void ExternalSource::run() {
	prctl(PR_SET_NAME, (unsigned long)&"gatord-uds", 0, 0, 0);

	while (gSessionData->mSessionIsActive) {
		// Will be aborted when the socket is closed at the end of the capture
		int length = mSock.receive(mBuffer.getWritePos(), mBuffer.contiguousSpaceAvailable());
		if (length <= 0) {
			break;
		}

		mBuffer.advanceWrite(length);
		mBuffer.check(0);
	}

	mBuffer.setDone();
}

void ExternalSource::interrupt() {
	// Do nothing
}

bool ExternalSource::isDone() {
	return mBuffer.isDone();
}

void ExternalSource::write(Sender *sender) {
	if (!mBuffer.isDone()) {
		mBuffer.write(sender);
	}
}