コード例 #1
0
ファイル: client.cpp プロジェクト: hanchen999/OS94
void displayLoop(socket_ptr sock)
{
    for(;;)
    {       
        if(!messageQueue->empty())
        {
            if(!isOwnMessage(messageQueue->front()))
            {
                cout << "\n" + *(messageQueue->front()) << endl;
            }
            
            messageQueue->pop();
        }
        
        boost::this_thread::sleep( boost::posix_time::millisec(50));
    }
}
コード例 #2
0
void displayLoop(socket_ptr sock)
{
    for(;;)
    {
        if(!messageQueue->empty())
        {
            if(!isOwnMessage(messageQueue->front()))
            {
                cout << "\n" + *(messageQueue->front());
		mainMutex.lock();
		recvMessage.insert(0,*(messageQueue->front()));
		mainMutex.unlock();
            }
		
            messageQueue->pop();
        }

        boost::this_thread::sleep( boost::posix_time::millisec(1000));
    }
}
コード例 #3
0
void displayLoop(socket_ptr sock)
{
    for(;;)
    {
        if(!messageQueue->empty())
        {
            if(!isOwnMessage(messageQueue->front()))
            {
                string strTemp = *(messageQueue->front());
                cerr << "message received:" << strTemp.c_str() << ":\n";
                mainMutex.lock();
                recvMessage.clear();
                recvMessage.append(strTemp.c_str());
                mainMutex.unlock();
            }
            messageQueue->pop();
        }

        boost::this_thread::sleep( boost::posix_time::millisec(50));
    }
}
コード例 #4
0
ファイル: server.cpp プロジェクト: LudwikJaniuk/chat_test
void responseLoop()
{
	for(;;)
	{
		if(!messageQueue->empty())
		{
			auto message = messageQueue->front();

			mtx.lock();
			for(auto& clientSock : *clientList)
			{
				clientSock->write_some(buffer(*(message->begin()->second), bufSize));
			}
			mtx.unlock();

			mtx.lock();
			messageQueue->pop();
			mtx.unlock();
		}

		boost::this_thread::sleep( boost::posix_time::millisec(sleepLen::lon));
	}
}
コード例 #5
0
void inboundLoop(socket_ptr sock, string_ptr prompt)
{
    int bytesRead = 0;
    char readBuf[1024] = {0};

    for(;;)
    {
        if(sock->available())
        {
            bytesRead = sock->read_some(buffer(readBuf, inputSize));
            string_ptr msg(new string(readBuf, bytesRead));

            messageQueue->push(msg);
        }

        boost::this_thread::sleep( boost::posix_time::millisec(1000));
    }
}
コード例 #6
0
ファイル: client.cpp プロジェクト: hanchen999/OS94
void inboundLoop(socket_ptr sock, string_ptr prompt)
{
    std::size_t bytesRead = 0;
    char readBuf[1024] = {0};
    
    for(;;)
    {
        if(sock->is_open() && sock->available())
        {
            bytesRead = sock->read_some(buffer(readBuf, inputSize));
            string_ptr msg(new string(readBuf, bytesRead));
            
            messageQueue->push(msg);
            cout << "messages received correctly" << endl;
        }
        
        boost::this_thread::sleep( boost::posix_time::millisec(50));
    }
}
コード例 #7
0
ファイル: server.cpp プロジェクト: LudwikJaniuk/chat_test
void requestLoop()
{
	for(;;)
	{
		if(!clientList->empty())
		{
			// Poorly designed loop, client sockets 
			// should alert the server when they have new messages; 
			// the server shouldn't poll the clientList while holding a lock
			mtx.lock();
			for(auto& clientSock : *clientList)
			{
				if(clientSock->available())
				{
					char readBuf[bufSize] = {0};

					int bytesRead = clientSock->read_some(buffer(readBuf, bufSize));

					string_ptr msg(new string(readBuf, bytesRead));

					if(clientSentExit(msg))
					{
						disconnectClient(clientSock);
						break;
					}

					clientMap_ptr cm(new clientMap);
					cm->insert(pair<socket_ptr, string_ptr>(clientSock, msg));

					messageQueue->push(cm);

					cout << "ChatLog: " << *msg << endl;
				}
			}
			mtx.unlock();
		}

		boost::this_thread::sleep( boost::posix_time::millisec(sleepLen::lon));
	}
}