summaryrefslogtreecommitdiff
path: root/src/socketengines/socketengine_eventfd.cpp
blob: a0efe528684279580cfd3504b64f0382f6756df4 (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
#include "services.h"
#include <sys/eventfd.h>

int Pipe::RecvInternal(char *buf, size_t sz) const
{
	static eventfd_t dummy;
	return !eventfd_read(this->Sock, &dummy);
}

int Pipe::SendInternal(const Anope::string &) const
{
	return !eventfd_write(this->Sock, 1);
}

Pipe::Pipe() : Socket()
{
	this->Sock = eventfd(0, EFD_NONBLOCK);
	if (this->Sock < 0)
		throw CoreException(Anope::string("Could not create pipe: ") + Anope::LastError());

	this->IPv6 = false;
	this->Type = SOCKTYPE_CLIENT;

	SocketEngine->AddSocket(this);
}

bool Pipe::ProcessRead()
{
	this->RecvInternal(NULL, 0);
	return this->Read("");
}

bool Pipe::Read(const Anope::string &)
{
	this->OnNotify();
	return true;
}

void Pipe::Notify()
{
	this->Write("*");
}

void Pipe::OnNotify()
{
}