C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[621] Indy(인디) TCPServer에서 종료때나 Active를 false로 할 때 Terminate Thread Timeout 처리
박영목 [gsbsoft] 9620 읽음    2006-11-10 14:24
저는 C++Builder를 사용하여 프로그램 중입니다.  인디 9.0.18 에서 ...
델마당에 답변으로 올리고 왔는데... 여기도 없을 것 같아... 아니 제가 찾아보니 없더군요....
이것 때문에 반나절을 보내 버렸네.... ㅋㅋㅋㅋ

TIdTCPServer에서 클라이언트가 Connect 되어 있을 때 종료하면 .... 피곤한 Error 발생하더군요....
좀처럼 막을 수 없었는데.... 답을 찾았습니다.

//-----------------------------------------------------------

저도 이것 때문에 황당하더군요.. 그리고 님의 글을 보고 이것이 Indy의 버그로 알려졌다는 것을 알았습니다. 그래서 아... 마음을 좀 놓고 해결을 위해 google을 뒤빈 결과 아래가 나왔는데.... Disconnect 부분은 DB에 관계된 일 같고,....

그냥  Connect 부분에서

AThread.FreeOnTerminate := True;

을 하나 추가해 주니 Error가 발생하지 않습니다.

개발자들에 대한 개발자의 배려인지... 함정인지... 프로그램 20년 되어 가는데... 아직 부산에서 밤늣도록 노가다 하고 있는 나에게는 함정이다....


오랜만에 글을 올렸네요.....   좋은 하루 ... 되세요....


你不可能通过athread来断开,每个连接都要保存为连接线程,放到threadlist里面,断开的话也只是在threadlist里面选一个断开,不可能只通过athread就能全部实现
看看我的连接和断开代码
procedure Tfrm_ServerMain.TCPServerConnect(AThread: TIdPeerThread);
begin
iUserCount := iUserCount + 1;
stbMain.Panels[0].Text := '连接用户个数:' + IntToStr(iUserCount);

MyList.LockList.Add(Pointer(AThread));
MyList.UnlockList;
AThread.FreeOnTerminate := True;
end;

procedure Tfrm_ServerMain.TCPServerDisconnect(AThread: TIdPeerThread);
var
i : integer;
SetStatMsg : TMyMsg;
begin
iUserCount := iUserCount - 1;
stbMain.Panels[0].Text := '连接用户个数:' + IntToStr(iUserCount);

if AThread.Data <> nil then
begin

  { qryDisconn.Close;
   qryDisconn.SQL.Text := 'Select * from tb_User a, tb_Friends b  '
       + 'where a.fUserName = b.fFriendsName  and a.fstat = 0 and b.fUsername = ' + QuotedStr(TFriendMsg(AThread.Data).UserName);
   qryDisconn.Open; }
   qryDisconn.Close;
   qryDisconn.SQL.Text := 'Select * from tb_User  where '
       + ' fstat <> 9 and fUsername <> ' + QuotedStr(TFriendMsg(AThread.Data).UserName);
   qryDisconn.Open;


   if qryDisconn.RecordCount > 0 then
   begin
     qryDisconn.First;
     while not qryDisconn.Eof do
     begin
       SetStatMsg.iType := 2;
       SetStatMsg.iFile := 0;
       SetStatMsg.iSize := 0;
       SetStatMsg.istat := 9;
       SetStatMsg.Pwd := '';
       SetStatMsg.RecName := qryDisconn.FieldValues['fUserName'];
       SetStatMsg.UserName := TFriendMsg(AThread.Data).UserName;
       SetStatMsg.sIP := '';
       SetStatMsg.sMsg := '';
       i := lbxUser.Items.IndexOf(qryDisconn.FieldValues['fUserName']);
       TIdPeerThread(MyList.LockList.Items[i]).Connection.WriteBuffer(SetStatMsg,sizeof(SetStatMsg),True);
       MyList.UnlockList;
      
       qryDisconn.Next;
     end;
   end;

   if qryMain.Locate('fUserName',TFriendMsg(AThread.Data).UserName,[]) then    //用户下线
   begin
     qryMain.Edit;
     qryMain.FieldValues['fStat'] := 9;
     qryMain.FieldValues['fLogIP'] := '';
     qryMain.Post;
   end;

   AThread.Data := nil;
end; 

i := MyList.LockList.IndexOf(Pointer(AThread));
MyList.UnlockList;
MyList.LockList.Remove(Pointer(AThread));
MyList.UnlockList;

//AThread.Free;
lbxUser.Items.Delete(i);
end;

+ -

관련 글 리스트
621 Indy(인디) TCPServer에서 종료때나 Active를 false로 할 때 Terminate Thread Timeout 처리 박영목 9620 2006/11/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.