fixed locks and memleak

This commit is contained in:
André Mussche 2014-08-01 12:19:25 +02:00
parent f79c3cdb8a
commit be9eb84f89
2 changed files with 72 additions and 52 deletions

View file

@ -237,6 +237,7 @@ begin
// FHeartBeat.OnTimer := HeartBeatTimer;
FWriteTimeout := 2 * 1000;
ConnectTimeout := 2000;
end;
procedure TIdHTTPWebsocketClient.AsyncDispatchEvent(const aEvent: TStream);
@ -367,9 +368,12 @@ begin
FSocketIO.WriteDisConnect(FSocketIOContext as TSocketIOContext)
else
FSocketIO.FreeConnection(FSocketIOContext as TSocketIOContext);
// IInterface(FSocketIOContext)._Release;
FSocketIOContext := nil;
Lock;
try
if IOHandler <> nil then
begin
IOHandler.Lock;
@ -386,6 +390,9 @@ begin
IOHandler.Unlock;
end;
end;
finally
UnLock;
end;
end;
function TIdHTTPWebsocketClient.GetIOHandlerWS: TIdIOHandlerWebsocket;
@ -779,6 +786,8 @@ procedure TIdHTTPWebsocketClient.Ping;
var
ws: TIdIOHandlerWebsocket;
begin
if TryLock then
try
ws := IOHandler as TIdIOHandlerWebsocket;
ws.LastPingTime := Now;
@ -803,6 +812,9 @@ begin
ws.Unlock;
end;
end;
finally
Unlock;
end;
end;
procedure TIdHTTPWebsocketClient.ReadAndProcessData;
@ -1244,6 +1256,9 @@ begin
FReconnectThread.Free;
end;
if FReconnectlist <> nil then
FReconnectlist.Free;
IdWinsock2.closesocket(FTempHandle);
FTempHandle := 0;
FChannels.Free;
@ -1508,6 +1523,8 @@ begin
chn := TIdHTTPWebsocketClient(l.Items[i]);
if chn.NoAsyncRead then Continue;
if chn.TryLock then
try
ws := chn.IOHandler as TIdIOHandlerWebsocket;
if (ws = nil) then Continue;
@ -1527,6 +1544,9 @@ begin
finally
ws.Unlock;
end;
finally
chn.Unlock;
end;
end;
if FPendingBreak then

View file

@ -186,7 +186,7 @@ type
procedure WriteSocketIOJSON(const ASocket: ISocketIOContext; const aRoom, aJSON: string; aCallback: TSocketIOCallbackRef = nil; const aOnError: TSocketIOError = nil);
procedure WriteSocketIOEvent(const ASocket: ISocketIOContext; const aRoom, aEventName, aJSONArray: string; aCallback: TSocketIOCallback; const aOnError: TSocketIOError);
procedure WriteSocketIOEventRef(const ASocket: ISocketIOContext; const aRoom, aEventName, aJSONArray: string; aCallback: TSocketIOCallbackRef; const aOnError: TSocketIOError);
function WriteSocketIOEventSync(const ASocket: ISocketIOContext; const aRoom, aEventName, aJSONArray: string; aMaxwait_ms: Integer = INFINITE): ISuperObject;
function WriteSocketIOEventSync(const ASocket: ISocketIOContext; const aRoom, aEventName, aJSONArray: string; aMaxwait_ms: Cardinal = INFINITE): ISuperObject;
procedure WriteSocketIOResult(const ASocket: ISocketIOContext; aRequestMsgNr: Integer; const aRoom, aData: string);
procedure ProcessSocketIO_XHR(const aGUID: string; const aStrmRequest, aStrmResponse: TStream);
@ -229,7 +229,7 @@ type
public
procedure Send(const aMessage: string; const aCallback: TSocketIOMsgJSON = nil; const aOnError: TSocketIOError = nil);
procedure Emit(const aEventName: string; const aData: ISuperObject; const aCallback: TSocketIOMsgJSON = nil; const aOnError: TSocketIOError = nil);overload;
function EmitSync(const aEventName: string; const aData: ISuperObject; aMaxwait_ms: Integer = INFINITE): ISuperobject;
function EmitSync(const aEventName: string; const aData: ISuperObject; aMaxwait_ms: Cardinal = INFINITE): ISuperobject;
//procedure Emit(const aEventName: string; const aData: string; const aCallback: TSocketIOMsgJSON = nil; const aOnError: TSocketIOError = nil);overload;
end;
@ -760,7 +760,7 @@ begin
begin
Lock;
try
ASocket._AddRef;
//ASocket._AddRef;
FConnections.Add(nil, socket); //clients do not have a TIdContext?
finally
UnLock;
@ -949,7 +949,7 @@ begin
if not FConnections.ContainsValue(ASocket) and
not FConnectionsGUID.ContainsValue(ASocket) then
begin
ASocket._AddRef;
//ASocket._AddRef;
FConnections.Add(nil, ASocket); //clients do not have a TIdContext?
end;
@ -1050,7 +1050,7 @@ begin
end;
function TIdBaseSocketIOHandling.WriteSocketIOEventSync(const ASocket: ISocketIOContext; const aRoom, aEventName,
aJSONArray: string; aMaxwait_ms: Integer = INFINITE): ISuperObject;
aJSONArray: string; aMaxwait_ms: Cardinal = INFINITE): ISuperObject;
var
sresult: string;
inr: Integer;
@ -1579,7 +1579,7 @@ begin
end;
end;
function TIdSocketIOHandling.EmitSync(const aEventName: string; const aData: ISuperObject; aMaxwait_ms: Integer = INFINITE): ISuperobject;
function TIdSocketIOHandling.EmitSync(const aEventName: string; const aData: ISuperObject; aMaxwait_ms: Cardinal = INFINITE): ISuperobject;
var
firstcontext, context: ISocketIOContext;
jsonarray: string;