XE8-indy10에서 TIDTCPClient 컨트롤 Disconnect 소스 분석
procedure TIdTCPConnection.Disconnect(ANotifyPeer: Boolean);
var
// under ARC, convert a weak reference to a strong reference before working with it
LIOHandler: TIdIOHandler;
begin
try
// Separately to avoid calling .Connected unless needed
if ANotifyPeer then begin
// overriden. Ideally, Connected() should be called by overridden
// DisconnectNotifyPeer() implementations if they really need it. But
// to avoid any breakages in third-party overrides, we could check here
// if DisconnectNotifyPeer() has been overridden and then call Connected()
// to maintain existing behavior...
//
if Connected then begin
DisconnectNotifyPeer;
end;
end;
finally
{
there are a few possible situations here:
1) we are still connected, then everything works as before,
status disconnecting, then disconnect, status disconnected
2) we are not connected, and this is just some "rogue" call to
disconnect(), then nothing happens
3) we are not connected, because ClosedGracefully, then
LConnected will be false, but the implicit call to
CheckForDisconnect (inside Connected) will call the events
}
// We dont check connected here - we realy dont care about actual socket state
// Here we just want to close the actual IOHandler. It is very possible for a
// socket to be disconnected but the IOHandler still open. In this case we only
// care of the IOHandler is still open.
//
// This is especially important if the socket has been disconnected with error, at this
// point we just want to ignore it and checking .Connected would trigger this. We
// just want to close. For some reason NS 7.1 (And only 7.1, not 7.0 or Mozilla) cause
// CONNABORTED. So its extra important we just disconnect without checking socket state.
LIOHandler := IOHandler;
if Assigned(LIOHandler) then begin
if LIOHandler.Opened then begin
DoStatus(hsDisconnecting);
LIOHandler.Close;
DoOnDisconnected;
DoStatus(hsDisconnected);
//LIOHandler.InputBuffer.Clear;
end;
end;
end;
end;
주석:
{
there are a few possible situations here:
1) we are still connected, then everything works as before,
status disconnecting, then disconnect, status disconnected
2) we are not connected, and this is just some "rogue"call to
disconnect(), then nothing happens
3) we are not connected, because ClosedGracefully, then
LConnected will be false, but the implicit call to
CheckForDisconnect (inside Connected) will call the events
}
//We dont check connected here - we realy dont care about actual socket state
//Here we just want to close the actual IOHandler. It is very possible for a
//socket to be disconnected but the IOHandler still open. In this case we only
//care of the IOHandler is still open.
//
//This is especially important if the socket has been disconnected with error, at this
//point we just want to ignore it and checking .Connected would trigger this. We
//just want to close. For some reason NS 7.1 (And only 7.1, not 7.0 or Mozilla) cause
//CONNABORTED. So its extra important we just disconnect without checking socket state.
//CONNABORTED. So its extra important we just disconnect without checking socket state.
중국어 번역(정확하지 않을 수도 있음):
몇 가지 가능한 상황:
1) 정상적인 연결은 다른 일이 발생하기 전에 상태가 연결을 끊는 중으로 변한 다음에 연결을 끊고 마지막 상태가 연결을 끊는 것으로 변한다.
2) 연결이 없고 일부 깡패들이 연결 끊기 함수를 호출하면 아무 일도 일어나지 않는다.
3) 연결이 없으나 Closed Gracefully 때문에 (CheckForDisconnect 호출이 표시되지 않는 한 Lconnected에서 오류가 발생합니다.
소스 코드의 CheckForDisconnect 프로토타입과 메모를 첨부합니다.
// CheckForDisconnect allows the implementation to check the status of the
// connection at the request of the user or this base class.
procedure CheckForDisconnect(ARaiseExceptionIfDisconnected: Boolean = True;
AIgnoreBuffer: Boolean = False); virtual; abstract;
원본 코드 어딘가의 주해에 의하면
// Check here as other side may have closed connection
CheckForDisconnect(ARaiseExceptionIfDisconnected);
//Check here as other side may have closed connection
여기에서 다른 쪽 연결이 닫혔는지 확인
그래서 CheckForDisconnect는 상대방의 연결이 끊겼는지 확인하는 함수라고 생각합니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[Delphi] TStringBuilder그리고 꼭 사용해야만 할까? 그림처럼 Heap 영역에 "Hello" 공간을 생성하고 포인팅을 한다. "Hello World" 공간을 새로 생성한 후 포인팅을 하게 된다. 결국 "Hello" 라는 String 객체가 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.