当前位置: 首页>>代码示例>>C++>>正文


C++ Singleton::Add方法代码示例

本文整理汇总了C++中Singleton::Add方法的典型用法代码示例。如果您正苦于以下问题:C++ Singleton::Add方法的具体用法?C++ Singleton::Add怎么用?C++ Singleton::Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Singleton的用法示例。


在下文中一共展示了Singleton::Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ClientThread

DWORD WINAPI Server::ClientThread(LPVOID lpParam) //(insert to DEQUE) use MUTEX
{
	Singleton* log = Singleton::Instance();
	log->Add("Thread: Client runing");

	SOCKET sock = (SOCKET)lpParam; //Get socket

	while(f)
	{
		//recv DATA, create STRUCTURE and (insert to DEQUE)MUTEX
		//Send will be in APPLY THREAD
		if ( recv(sock,rdata.ch,sizeof(DWORD),0) != -1 ) //Wait data //save data to union
		{
			Message tmp;
			tmp.s = sock;
			tmp.data = rdata.i;

			WaitForSingleObject(hMutex,INFINITE);
			deque_data.push_back(tmp);
			ReleaseMutex(hMutex);
		}
		else
		{
			break;
		}
	}
	
	log->Add("Thread: Client stoped");
	return 0;
}
开发者ID:VIC373,项目名称:Source,代码行数:30,代码来源:Server.cpp

示例2: Activate

bool Server::Activate(int userCount = 5, int port = 7500)
{
	Singleton* log = Singleton::Instance();

	if ( port <= 0 || port >= 65535 || userCount <= 0 )
	{
		log->Add("Server: Bad activation data");
		return false;
	}
	
	if ( WSAStartup(MAKEWORD(2,2),&wsadata) != 0)
	{
		log->Add("Server: Err WSADATA");
		return false;
	}
	log->Add("Server: WSA activate");

	if ( (serv = socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET )
	{
		log->Add("Server: INVALID SOCKET");
		return false;
	}
	log->Add("Server: Socket activate");

	local.sin_family= AF_INET;
	local.sin_port = htons(port);
	local.sin_addr.s_addr = htonl(INADDR_ANY); // ALL IP

	if ( bind(serv,(struct sockaddr*)&local,sizeof(local)) != 0 ) //0 - done
	{
		log->Add("Server: Bind err");
		return false;
	}
	log->Add("Server: Bind done");

	if ( listen(serv,userCount) != 0 )
	{
		log->Add("Server: listen err");
		return false;
	}
	log->Add("Server: listen done");
	log->Add("Server: activate done");

	hMutex = CreateMutex(NULL,false,NULL);//Create mutex for all threads
	HANDLE hT = CreateThread(NULL,NULL,Server::Accept,NULL,NULL,NULL); //CreateThread for accept
	HANDLE hT2 = CreateThread(NULL,NULL,Server::Apply,NULL,NULL,NULL); //Create APPLY thread
	CloseHandle(hT);
	CloseHandle(hT2);
	return true;
}
开发者ID:VIC373,项目名称:Source,代码行数:50,代码来源:Server.cpp

示例3: Accept

DWORD WINAPI Server::Accept(LPVOID)
{
	Singleton* log = Singleton::Instance();
	log->Add("Thread: Accept runing");
	
	while (f)
	{
		int size = sizeof(client);
		s = accept(serv,(struct sockaddr*)&client,&size);

		//create thread vs new SOCKET
		HANDLE hThread = CreateThread(NULL,NULL,ClientThread,(LPVOID)s,NULL,NULL);
		CloseHandle(hThread);
	}

	log->Add("Thread: Accept stoped");
	return 0;
}
开发者ID:VIC373,项目名称:Source,代码行数:18,代码来源:Server.cpp

示例4: Apply

DWORD WINAPI Server::Apply(LPVOID) // (Get structure from DEQUE)use MUTEX
{
	Singleton* log = Singleton::Instance();
	log->Add("Thread: Apply running");

	while(f)
	{
		//(Get structure from deque)MUTEX ....calculation with data and send data 
		WaitForSingleObject(hMutex,INFINITE);

			if ( !deque_data.empty() )
			{
				sdata.i = deque_data.front().data * 2; //Information to UNION 
				SOCKET s = deque_data.front().s; //Get Socket
				deque_data.pop_front();
				send(s,sdata.ch,sizeof(DWORD),0);
			}
		ReleaseMutex(hMutex);
		Sleep(1); //CPU 100%
	}

	log->Add("Thread: Applay stoped");
	return 0;
}
开发者ID:VIC373,项目名称:Source,代码行数:24,代码来源:Server.cpp


注:本文中的Singleton::Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。