Open GoogleCodeExporter opened 9 years ago
function TIocpMultiAcceptThread.AddListen(aServer: TTcpConnectionServer):
Boolean;
begin
FAcceptEventLocker.Enter;
Result := FServerCount <= 63;
if Result then
begin
FAcceptEventType := etAdd;
FAcceptEventServer := aServer;
SetEvent(FAcceptEvent);
end
else
FAcceptEventLocker.Leave;
end;
procedure TIocpMultiAcceptThread.DoAddListen;
var
i: Integer;
begin
FServers[FServerCount] := FAcceptEventServer;
// FListenSocket[High(FServers)].FContext:=FAcceptEventSocketContext;
for i := 1 to FAcceptEventServer.FParam.InitAcceptNum - 1 do
FOwner.PostNewAcceptEx(FServers[FServerCount].FListenSocket, FAiFamily);
FAcceptEvents[FServerCount] := WSACreateEvent;
// 绑定监听端口的ACCEPT事件,当没有足够的Accept套接字时就会触发该事件
WSAEventSelect(FAcceptEventServer.FListenSocket, FAcceptEvents[FServerCount], FD_ACCEPT);
Inc(FServerCount);
FAcceptEvents[FServerCount] := FAcceptEvent;
FAcceptEventLocker.Leave;
end;
procedure TIocpMultiAcceptThread.DelListen(aServer: TTcpConnectionServer);
begin
FAcceptEventLocker.Enter;
FAcceptEventType := etDel;
FAcceptEventServer := aServer;
SetEvent(FAcceptEvent);
end;
procedure TIocpMultiAcceptThread.DoDelListen;
var
i: Integer;
begin
for i := 0 to FServerCount-1 do
begin
if FServers[i] = FAcceptEventServer then
begin
FOwner.CloseSocket(FAcceptEventServer.FListenSocket);
CloseHandle(FAcceptEvents[i]);
FServers[i].DoStop;
FServers[i].Free;
if i <> High(FServers) then
Move(FServers[i + 1], FServers[i], FServerCount - i);
Move(FAcceptEvents[i + 1], FAcceptEvents[i], FServerCount+1 - i);
Dec(FServerCount);
Break;
end;
end;
FAcceptEventLocker.Leave;
end;
Original comment by Hezihang...@gmail.com
on 27 May 2013 at 2:46
你的程序在添加Listen或删除Listen可能会存在问题,因为
dwRet := WSAWaitForMultipleEvents(FServerCount+1, @FAcceptEvents[0], False, INFINITE, True);
并没有及时把新的Listen加入Wait或者没有及时把删除Listen的Even
t从FAcceptEvents删除,
我的程序不会有这个问题,请参考我的程序.
Original comment by Hezihang...@gmail.com
on 27 May 2013 at 2:52
[deleted comment]
1、等空余时间多一点,这个我会考虑
2、你更新最新的代码看看,应该没这个问题
Original comment by soulaw...@gmail.com
on 31 May 2013 at 1:37
在IOAcceptThread中,Quit和New Listen
事件可以用一个Event,这样一个线程可以多侦听一个端口,另
外IoAcceptThread的Reset和AddListen仍然可能存在被多个线程同时访�
��,导致数据错误。
你可以参考看一下上面我的程序中的AddListen,DelListen等实现��
�式。
Original comment by Hezihang...@gmail.com
on 1 Jun 2013 at 1:30
Original issue reported on code.google.com by
Hezihang...@gmail.com
on 27 May 2013 at 7:39