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

Pipe::Pipe() : Socket(-1)
{
	sockaddrs localhost;

	localhost.pton(AF_INET, "127.0.0.1");

	int cfd = socket(AF_INET, SOCK_STREAM, 0), lfd = socket(AF_INET, SOCK_STREAM, 0);
	if (cfd == -1)
		throw CoreException("Error accepting new socket for Pipe");
	
	if (bind(lfd, &localhost.sa, localhost.size()) == -1)
		throw CoreException("Error accepting new socket for Pipe");
	if (listen(lfd, 1) == -1)
		throw CoreException("Error accepting new socket for Pipe");

	sockaddrs lfd_addr;
	socklen_t sz = sizeof(lfd_addr);
	getsockname(lfd, &lfd_addr.sa, &sz);

	if (connect(cfd, &lfd_addr.sa, lfd_addr.size()))
		throw CoreException("Error accepting new socket for Pipe");
	CloseSocket(lfd);
	
	this->WritePipe = cfd;

	SocketEngine::AddSocket(this);
}

Pipe::~Pipe()
{
	CloseSocket(this->WritePipe);
}

bool Pipe::ProcessRead()
{
	char dummy[512];
	while (recv(this->GetFD(), dummy, 512, 0) == 512);
	this->OnNotify();
	return true;
}

void Pipe::Notify()
{
	const char dummy = '*';
	send(this->WritePipe, &dummy, 1, 0);
}

void Pipe::OnNotify()
{
}