本文整理汇总了C++中CGXByteBuffer::Capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ CGXByteBuffer::Capacity方法的具体用法?C++ CGXByteBuffer::Capacity怎么用?C++ CGXByteBuffer::Capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGXByteBuffer
的用法示例。
在下文中一共展示了CGXByteBuffer::Capacity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ListenerThread
void ListenerThread(void* pVoid)
{
CGXByteBuffer reply;
CGXDLMSBase* server = (CGXDLMSBase*)pVoid;
sockaddr_in add = { 0 };
int ret;
char tmp[10];
CGXByteBuffer bb;
bb.Capacity(2048);
#if defined(_WIN32) || defined(_WIN64)//If Windows
int len;
int AddrLen = sizeof(add);
SOCKET socket;
#else //If Linux
socklen_t len;
socklen_t AddrLen = sizeof(add);
int socket;
#endif
struct sockaddr_in client;
memset(&client, 0, sizeof(client));
//Get buffer data
basic_string<char> senderInfo;
while (server->IsConnected())
{
len = sizeof(client);
senderInfo.clear();
socket = accept(server->GetSocket(), (struct sockaddr*)&client, &len);
server->Reset();
if (server->IsConnected())
{
server->Reset();
if ((ret = getpeername(socket, (sockaddr*)&add, &AddrLen)) == -1)
{
closesocket(socket);
#if defined(_WIN32) || defined(_WIN64)//If Windows
socket = INVALID_SOCKET;
#else //If Linux
socket = -1;
#endif
continue;
//Notify error.
}
senderInfo = inet_ntoa(add.sin_addr);
senderInfo.append(":");
#if _MSC_VER > 1000
_ltoa_s(add.sin_port, tmp, 10, 10);
#else
sprintf(tmp, "%d", add.sin_port);
#endif
senderInfo.append(tmp);
while (server->IsConnected())
{
//If client is left wait for next client.
if ((ret = recv(socket, (char*)
bb.GetData() + bb.GetSize(),
bb.Capacity() - bb.GetSize(), 0)) == -1)
{
//Notify error.
server->Reset();
#if defined(_WIN32) || defined(_WIN64)//If Windows
closesocket(socket);
socket = INVALID_SOCKET;
#else //If Linux
close(socket);
socket = -1;
#endif
break;
}
//If client is closed the connection.
if (ret == 0)
{
server->Reset();
#if defined(_WIN32) || defined(_WIN64)//If Windows
closesocket(socket);
socket = INVALID_SOCKET;
#else //If Linux
close(socket);
socket = -1;
#endif
break;
}
bb.SetSize(bb.GetSize() + ret);
if (server->m_Trace == GX_TRACE_LEVEL_VERBOSE)
{
printf("RX:\t%s\r\n", bb.ToHexString().c_str());
}
if (server->HandleRequest(bb, reply) != 0)
{
#if defined(_WIN32) || defined(_WIN64)//If Windows
closesocket(socket);
socket = INVALID_SOCKET;
#else //If Linux
close(socket);
socket = -1;
#endif
}
bb.SetSize(0);
if (reply.GetSize() != 0)
{
if (server->m_Trace == GX_TRACE_LEVEL_VERBOSE)
//.........这里部分代码省略.........