Skip to content

Commit

Permalink
Do not free the MQTT socket when reconnecting after an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name Comes Here committed Dec 8, 2016
1 parent 0b6d56b commit 9b24fb7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions TMQTTClient/MQTT.pas
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ TMQTTClient = class(TObject)
var
Data: TBytes;
begin
writeln('TMQTTClient.Disconnect');
Result := False;

SetLength(Data, 2);
Expand All @@ -269,7 +270,7 @@ TMQTTClient = class(TObject)
FReadThread.waitFor;
FSocket.CloseSocket;
FisConnected := False;
FSocket.Free;
FSocket := nil;
end
else Result := False;
end;
Expand All @@ -283,6 +284,7 @@ TMQTTClient = class(TObject)
------------------------------------------------------------------------------*}
procedure TMQTTClient.ForceDisconnect;
begin
writeln('TMQTTClient.ForceDisconnect');
if FReadThread <> nil then
begin
FReadThread.Terminate;
Expand All @@ -291,7 +293,6 @@ TMQTTClient = class(TObject)
if FSocket <> nil then
begin
FSocket.CloseSocket;
FSocket.Free;
FSocket := nil;
end;
FisConnected := False;
Expand Down
1 change: 1 addition & 0 deletions TMQTTClient/MQTTReadThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ TMQTTReadThread = class(TThread)
multiplier := 1;
remainingLengthx := 0;
CurrentMessage.Data := nil;

CurrentMessage.FixedHeader := FPSocket^.RecvByte(1000);
if (FPSocket^.LastError = ESysETIMEDOUT) then continue;
if (FPSocket^.LastError <> 0) then
Expand Down

0 comments on commit 9b24fb7

Please sign in to comment.