双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

IOhandler->Write的问题

kagagas kagagas 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
开发的软件中遇到了一个奇怪的问题,TIdTCPServer->Contexts->LockList()之后,用其中的连接信息给每个终端发送一张图像,但是总是有BUG,软件在使用时不定期的卡死,我记的日志就显示就在下面这个函数中,不定期的出现不能TIdTCPServer->Contexts->UnlockList()的现象(因为我的日志会在正常UnlockList之后删除),日志里都是在这个地方卡住,然后别的模块用到TIdTCPServer->Contexts->LockList()之后就一直排队不动了。。。。。。,求各位帮忙指点......
SendShareDesktop(UnicodeString MeetingID,UnicodeString UserID,TJPEGImage * Screen)throw(Exception) {
RecorderSet SendRS;
try {
TJPEGImage * ScreenJpeg = new TJPEGImage;
ScreenJpeg->Assign(Screen);

BaseRecorder * SendR = GetCustomRecorder(SHARE_DESKTOP_DATA_REQUEST);
SendR->Field("user_id")->AsString = UserID;
SendR->Field("screen")->AsJpeg = ScreenJpeg;
SendRS.AddRecorder(SendR);
}
catch(Exception & e) {
throw Exception("SendShareDesktop(1):"+e.Message);
}

int ListLog,ListCountLog;
try {
ListLog = AddLockLog(4,"连接列表加锁","SendShareDesktop");
TList * ContextList = EMTCPServer->Contexts->LockList();
ListCountLog = AddLockLog(5,"连接列表数量","SendShareDesktop:"+UnicodeString(ContextList->Count));


for(int i=0;i<ContextList->Count;i++) {
TIdContext * AContext = (TIdContext *)ContextList->Items[i];
UserSession * Session = (UserSession*)AContext->Data;
UnicodeString PeerIP = AContext->Connection->Socket->Binding->PeerIP;

if(Session) {
try {
SendEMPkg(AContext,SHARE_DESKTOP_DATA_REQUEST,SendRS.GetPkg(),SendRS.GetPkgLen());
}
catch(Exception & e) {
AddLog(SYS_WARNING,SQLString("SendShareDesktop(2):发送消息失败"),Session->IP);
}
}
else {
AddLog(SYS_WARNING,SQLString("SendShareDesktop(3):无Session信息,PeerIP:"+PeerIP),"EM_SERVICE");
}
}
}
__finally {
EMTCPServer->Contexts->UnlockList();
DeleteLockLog(ListCountLog);
DeleteLockLog(ListLog);

}
}

用到的SendEMPkg//---------------------------------------------------------------------------
void TXMServerService::SendEMPkg(TIdContext *AContext,unsigned OP,unsigned char * Pkg,int Size)throw(Exception)
{
UserSession * Session = (UserSession*)AContext->Data;
UnicodeString PeerIP = AContext->Connection->Socket->Binding->PeerIP;
if(Session && !PeerIP.IsEmpty() && AContext->Connection->Connected()) {
EMHeader Header;
Header.OP = OP;
Header.DataSize = Size;
HeaderCheck(&Header);

TMemoryStream * SendStream = NULL;
try {
Session->SendLock->Enter();
try {
SendStream = new TMemoryStream;
SendStream->Write(&Header,sizeof(Header));
SendStream->Write(Pkg,Size);
SendStream->Position = 0;
AContext->Connection->IOHandler->Write(SendStream,SendStream->Size);
}
catch(Exception & e) {
Session->Connected = false;
throw Exception("SendEMPkg(1):"+e.Message);
}
}
__finally {
if(SendStream)
delete SendStream;
Session->SendLock->Leave();
}
}
else {
throw Exception("SendEMPkg(2):Session信息丢失,PeerIP:"+PeerIP);
}
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
kagagas
网络及通讯开发 1,317 成员 8,874 内容