本文整理汇总了C++中TMemoryStream::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ TMemoryStream::Clear方法的具体用法?C++ TMemoryStream::Clear怎么用?C++ TMemoryStream::Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMemoryStream
的用法示例。
在下文中一共展示了TMemoryStream::Clear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AcceptClient
void TClientSockThread::AcceptClient()
{
int iResult;
int iSendResult;
char recvbuf[DEFAULT_BUFLEN];
char sandbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
bool IsData;
int CommandID, CurCommandID;
int DataType, CurDataType;
TMemoryStream *ms = new TMemoryStream;
if (Authentication(ClientSocket, ms)) {
CurCommandID = -1;
// Receive until the peer shuts down the connection
do {
iResult = recv(ClientSocket, recvbuf, recvbuflen, 0);
if (iResult > 0) {
Form1->m->Lines->Append("Bytes received: " + IntToStr(iResult));
CommandID = GetCommand(recvbuf, iResult);
if (CommandID == CM_EXEC) {
RunCommand( ClientSocket, CurCommandID, ms);
StrCopy(sandbuf, "ok\0");
iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
}
else if (CommandID) {
CurCommandID = CommandID;
ms->Clear();
StrCopy(sandbuf, "ok\0");
iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
}
else {
ms->Write(recvbuf, iResult);
StrCopy(sandbuf, "ok\0");
iSendResult = send( ClientSocket, sandbuf, strlen(sandbuf), 0 );
}
//
// Echo the buffer back to the sender
// iSendResult = send( ClientSocket, recvbuf, iResult, 0 );
// if (iSendResult == SOCKET_ERROR) {
// Form1->m->Lines->Append("send failed with error: " + IntToStr(WSAGetLastError()));
// closesocket(ClientSocket);
// WSACleanup();
// return;
// }
// Form1->m->Lines->Append("Bytes sent: " + IntToStr(iSendResult));
}
else if (iResult == 0)
Form1->m->Lines->Append("Connection closing...\n");
else {
Form1->m->Lines->Append("recv failed with error: " + IntToStr(WSAGetLastError()));
closesocket(ClientSocket);
WSACleanup();
delete ms;
return;
}
} while (iResult > 0);
}
// shutdown the connection since we're done
iResult = shutdown(ClientSocket, SD_SEND);
if (iResult == SOCKET_ERROR) {
Form1->m->Lines->Append("shutdown failed with error: " + IntToStr(WSAGetLastError()));
closesocket(ClientSocket);
WSACleanup();
delete ms;
return;
}
// cleanup
closesocket(ClientSocket);
delete ms;
}