void __fastcall TfrmMain::IdTCPServerExecute(TIdContext *AContext)
{
CoInitialize(NULL);
try
TCommHead Head = RecvHead(AContext->Connection);
TCommRequest Request = RecvRequest(AContext->Connection, Head);
TCommAnswer Answer;
Answer.Init();
switch (Head.CommType)
{
case cs_Comm_Request_OpenSQL:
{
TADOConnection *Connection = FPoolerMan->LockConnection(
AContext->Connection->Socket->Binding->Handle, Request.ConnectID);
if ( Connection == NULL )
{
Answer.ErrorNo = -1;
Answer.ErrorInfo = SERVER_IS_BUSY;
SendAnswer(Head.CommType, Answer, AContext->Connection);
}
else
{
Answer.ErrorNo = -1;
Answer.ErrorInfo = "无效的SQL";
SendAnswer(Head.CommType, Answer, AContext->Connection);
WriteLog("IP:" + AContext->Binding()->PeerIP + " " + Request.CommandText);
}
}
break;
}
case cs_Comm_Request_OpenFunc: // 执行功能,返回结果集
{
TADOConnection *Connection = FPoolerMan->LockConnection(
AContext->Connection->Socket->Binding->Handle, Request.ConnectID);
if ( Connection == NULL )
{
Answer.ErrorNo = -1;
Answer.ErrorInfo = SERVER_IS_BUSY;
SendAnswer(Head.CommType, Answer, AContext->Connection);
}
else
{
TMemoryStream *mm = new TMemoryStream();
try
{
SendAnswer(Head.CommType, Answer, AContext->Connection, mm);
}
__finally
{}
}
break;
}
}
default:
;
}
}
__finally
{
CoUninitialize;
}
}