本文整理汇总了C++中Protocol::Parse方法的典型用法代码示例。如果您正苦于以下问题:C++ Protocol::Parse方法的具体用法?C++ Protocol::Parse怎么用?C++ Protocol::Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Protocol
的用法示例。
在下文中一共展示了Protocol::Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
void Session::Run()
{
Command cmd;
while (true)
{
mQueue.WaitAndPop(cmd);
if (cmd == START)
{
cmd = NO_CMD;
if (mTcpClient.Connect(mHostName, mTcpPort) == true)
{
Protocol proto;
while (mInitialized)
{
if (mTcpClient.DataWaiting(200U))
{
std::string payload;
if (mTcpClient.Recv(payload))
{
proto.Add(payload);
std::string data;
while (proto.Parse(data))
{
// TLogNetwork("Found one packet with data: " + data);
std::vector<Reply> out;
std::uint32_t client_uuid = proto.GetDestUuid();
bool ret = mListener.Deliver(proto.GetSourceUuid(), client_uuid, data, out);
// Send synchronous data to the server
if (ret)
{
Send(out);
}
}
}
}
else
{
//std::cout << "client wait timeout or failure" << std::endl;
mInitialized = IsConnected(); // determine origine of failure
}
}
mListener.Signal(net::IEvent::ErrDisconnectedFromServer);
TLogNetwork("Client connection closed.");
}
else
{
TLogError("Client cannot connect to server.");
mListener.Signal(net::IEvent::ErrCannotConnectToServer);
}
}
else if (cmd == EXIT)
{
std::cout << "Exit client thread" << std::endl;
return;
}
}
}
示例2: WorkerThread
DWORD WINAPI CompletionPortStackListener::WorkerThread(LPVOID obj)
{
CompletionPortStackListener* instance = (CompletionPortStackListener*)obj;
int loopCtr1 = 0;
stack<Structs::LP_JOBREQUEST> _jobList = instance->jobList;
SOCKET _socket;
while (true)
{
::WaitForSingleObject(instance->ghHasMessageEvent, INFINITE);
::WaitForSingleObject(instance->ghMutex, INFINITE);
loopCtr1++;
::WaitForSingleObject(instance->ghMutex, INFINITE);
int sz = instance->jobList.size();
if (sz > 0)
{
::WaitForSingleObject(instance->ghMutex2, INFINITE);
Structs::LP_JOBREQUEST job = instance->jobList.top();
instance->jobList.pop();
::ReleaseMutex(instance->ghMutex2);
//
//
if (job == NULL)
{
continue;
}
_socket = job->socket;
{
try
{
Protocol* p = instance->_protocol; //*itr;
if (p == NULL)
{
continue;
}
Structs::LP_JOBREQUEST jobresp = new Structs::JOBREQUEST();
jobresp->data = job->data;
jobresp->len = job->len;
jobresp->socket = job->socket;
p->AddMessage(_strdup(jobresp->data));
LPVOID res = p->Parse();
Structs::LP_JOBREQUEST nextJob = (Structs::LP_JOBREQUEST)p->Next();
if (nextJob != NULL)
{
nextJob->socket = jobresp->socket;
instance->inputStage->AddMessage(nextJob);
}
if (job != NULL)
{
//ZeroMemory(job, sizeof(Structs::JOBREQUEST));
//delete(job);
}
}
catch (...)
{
int x = 1;
}
}
}
if (instance->jobList.size() == 0)
{
::ResetEvent(instance->ghHasMessageEvent);
}
::ReleaseMutex(instance->ghMutex);
}
return 1;
}