예제 #1
0
파일: UdpServer.cpp 프로젝트: 0cch/misc
UINT __stdcall UdpServerWorker(PVOID context)
{
	InitializeCriticalSection(&g_data_lock);
	UdpServer server;
	if (server.Init("127.0.0.1", (int)context)) {
		std::vector<UCHAR> buffer;
		buffer.resize(64 * 1024);
		for (;;) {
			sockaddr_in addr;
			int recv_length = server.Recv((char *)buffer.data(), buffer.size(), &addr);
			if (recv_length == -1) {
				break;
			}

			EnterCriticalSection(&g_data_lock);
			g_data_queue.push_back(std::vector<UCHAR>(buffer.begin(), buffer.begin() + recv_length));
			LeaveCriticalSection(&g_data_lock);
			SetEvent(g_data_event);

			server.Send("OK", 3, &addr);
		}
	}
	DeleteCriticalSection(&g_data_lock);
	return 0;
}
예제 #2
0
파일: UdpServer.cpp 프로젝트: 0cch/misc
UINT __stdcall UdpServerForIpWorker(PVOID context)
{
	UdpServer server;
	if (server.Init("127.0.0.1", (int)context)) {
		std::vector<UCHAR> buffer;
		buffer.resize(0x1000);
		for (;;) {
			sockaddr_in addr;
			int recv_length = server.Recv((char *)buffer.data(), buffer.size(), &addr);
			if (recv_length == -1) {
				break;
			}

			server.Send("OK", 3, &addr);
		}
	}

	return 0;
}