当前位置: 首页>>代码示例>>C++>>正文


C++ TMemoryStream::Clear方法代码示例

本文整理汇总了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;
}
开发者ID:IshPeredysh,项目名称:udd,代码行数:81,代码来源:TClientSockThread.cpp


注:本文中的TMemoryStream::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。