첫 번째 질문 :Indy 소켓 9에서 AccessViolation을받는 이유 IdTcpServer ServerExecute?
다음 루틴은 Indy 9 IdTcpServer.OnExecute 루틴의 올바른 구현입니까?
procedure TMyConnServer.ServerExecute(AContext: TIdPeerThread);
var
buffSize: integer;
str: string;
begin
AContext.Connection.ReadFromStack(True, 600, False);
buffSize := AContext.Connection.InputBuffer.Size;
if (buffSize > 0) then
{ Extract input buffer as string }
str := AContext.Connection.ReadString(buffSize);
{ Notify connection object of received data }
if (AContext.Data <> nil) then
begin
TConnectionHandler(AContext.Data).Read(str);
end;
end;
end;
초 (실제로 더 중요한) 질문 :
지금 가끔 액세스 위반이 (주소 000000 읽기). 분명히 라인 :
AContext.Connection.ReadFromStack(True, 600, False);
하지만 확인 AContext/연결/INPUTBUFFER/IOHandler = 전무는 전에 false 인 경우. 호출 후 (예외 발생 후) IOHandler는 nil입니다.
우리는 RAD 스튜디오/델파이 2007
글쎄, 네, 맞는 것 같아요. ServerExecute 함수가 중복되지 않기 때문에 (그렇습니까?) 단 하나의 CriticalSection을 사용하고 ServerExecute 내부에서 잠글 때 Disconnect를 수행 할 때 잠글 수 있습니까? – Tarnschaf
TIdTCPServer는 멀티 스레드 구성 요소입니다. 각 클라이언트 연결은 자체 스레드에서 실행됩니다. 따라서 OnExecute 이벤트 처리기는 서로 다른 스레드 컨텍스트에서 동시에 여러 번 실행할 수 있습니다. –
여러 스레드에서 읽거나 여러 스레드로 쓰지 않는 한 서버의 개별 클라이언트 연결에 대한 액세스를 잠글 필요가 없습니다 (일반적으로 잘못된 코드 디자인을 사용하는 것이 좋습니다). –