本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}