예제 #1
0
파일: uaeipc.cpp 프로젝트: engur/WinUAE
static int listenIPC (void *vipc)
{
	struct uaeipc *ipc = (struct uaeipc*)vipc;
	DWORD err;

	memset(&ipc->ol, 0, sizeof (OVERLAPPED));
	ipc->ol.hEvent = ipc->olevent;
	if (ConnectNamedPipe(ipc->hipc, &ipc->ol)) {
		write_log (_T("IPC: ConnectNamedPipe init failed, err=%d\n"), GetLastError());
		closeIPC(ipc);
		return 0;
	}
	err = GetLastError();
	if (err == ERROR_PIPE_CONNECTED) {
		if (SetEvent(ipc->olevent)) {
			write_log (_T("IPC: ConnectNamedPipe SetEvent failed, err=%d\n"), GetLastError());
			closeIPC(ipc);
			return 0;
		}
	} else if (err != ERROR_IO_PENDING) {
		write_log (_T("IPC: ConnectNamedPipe failed, err=%d\n"), err);
		closeIPC(ipc);
		return 0;
	}
	return 1;
}
예제 #2
0
파일: serwer.c 프로젝트: Wookesh/SO2
void endSafe()
{
	int i;
	fprintf(stderr,"Waiting for working threads\n");
	server.error = 1;
	for (i = 0; i < res.K; ++i) {
		pthread_cond_broadcast(&res.resources[i].waitForResources);
		pthread_cond_broadcast(&res.resources[i].waitForPair);
		pthread_cond_broadcast(&res.resources[i].waitInQueue);
	}
	waitForWorking();
	fprintf(stderr, "All threads finished\n");
	deleteResources();
	closeIPC();
}
예제 #3
0
파일: uaeipc.cpp 프로젝트: engur/WinUAE
void *createIPC (const TCHAR *name, int binary)
{
	TCHAR tmpname[100];
	int cnt = 0;
	struct uaeipc *ipc;

	ipc = xcalloc (struct uaeipc, 1);
	ipc->connected = FALSE;
	ipc->readpending = FALSE;
	ipc->writepending = FALSE;
	ipc->olevent = INVALID_HANDLE_VALUE;
	ipc->binary = 0;
	while (cnt < 10) {
		_stprintf (tmpname, _T("\\\\.\\pipe\\%s"), name);
		if (cnt > 0) {
			TCHAR *p = tmpname + _tcslen (tmpname);
			_stprintf (p, _T("_%d"), cnt);
		}
		ipc->hipc = CreateNamedPipe (tmpname,
			PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE,
			PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
			1, IPC_BUFFER_SIZE, IPC_BUFFER_SIZE,
			NMPWAIT_USE_DEFAULT_WAIT, NULL);
		if (ipc->hipc == INVALID_HANDLE_VALUE) {
			DWORD err = GetLastError ();
			if (err == ERROR_ALREADY_EXISTS || err == ERROR_PIPE_BUSY) {
				cnt++;
				continue;
			}
			return 0;
		}
		break;
	}
	write_log (_T("IPC: Named Pipe '%s' open\n"), tmpname);
	ipc->olevent = CreateEvent(NULL, TRUE, TRUE, NULL);
	if (listenIPC(ipc))
		return ipc;
	closeIPC(ipc);
	return NULL;
}