Skip to content

Commit

Permalink
Fix incorrect passing of keepalive values
Browse files Browse the repository at this point in the history
The C library expects integer seconds, while the Ada binding was passing
milliseconds.

Additionally, some versions have problems with a keepalive value of 0, so
the test is using 30, now.

See issue persan#1.
  • Loading branch information
mgrojo committed Dec 11, 2021
1 parent e5b0218 commit 640e315
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/mosquitto.adb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ package body Mosquitto is
(Mosq => Mosq.Handle,
Host => L_Host,
Port => Int (Port),
Keepalive => Int (Keepalive * 1000));
Keepalive => Int (Keepalive));
Free (L_Host);
Retcode_2_Exception (Ret);
Mosq.Wait_Until_Connected;
Expand Down Expand Up @@ -383,7 +383,7 @@ package body Mosquitto is
(Mosq => Mosq.Handle,
Host => L_Host,
Port => Int (Port),
Keepalive => Int (Keepalive * 1000),
Keepalive => Int (Keepalive),
Bind_Address => L_Bind_Address);
Free (L_Host);
Free (L_Bind_Address);
Expand All @@ -409,7 +409,7 @@ package body Mosquitto is
(Mosq => Mosq.Handle,
Host => L_Host,
Port => Int (Port),
Keepalive => Int (Keepalive * 1000));
Keepalive => Int (Keepalive));
Free (L_Host);
Retcode_2_Exception (Ret);
end Connect_Async;
Expand All @@ -434,7 +434,7 @@ package body Mosquitto is
(Mosq => Mosq.Handle,
Host => L_Host,
Port => Int (Port),
Keepalive => Int (Keepalive * 1000),
Keepalive => Int (Keepalive),
Bind_Address => L_Bind_Address);
Free (L_Host);
Free (L_Bind_Address);
Expand All @@ -459,7 +459,7 @@ package body Mosquitto is
Ret := Mosquitto_Connect_Srv
(Mosq => Mosq.Handle,
Host => L_Host,
Keepalive => Int (Keepalive * 1000),
Keepalive => Int (Keepalive),
Bind_Address => L_Bind_Address);
Free (L_Host);
Free (L_Bind_Address);
Expand Down Expand Up @@ -792,7 +792,7 @@ package body Mosquitto is

Package_Initialization_Controler : Controler with Unreferenced;

function Is_Initialzed (Mosq : Handle) return Boolean is
function Is_Initialzed (Mosq : Handle) return Boolean is
begin
return Mosq.Handle /= System.Null_Address;
end;
Expand Down
2 changes: 1 addition & 1 deletion src/mosquitto.ads
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ package Mosquitto is
-- port - the network port to connect to.
-- keepalive - the number of seconds after which the broker should send a PING
-- message to the client if no other messages have been exchanged
-- in that time.
-- in that time (decimal part will be ignored).

not overriding
procedure Set_Handler (Mosq : in out Handle;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/mosquitto-tests-main.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ begin
C.Initialize (GNAT.Sockets.Host_Name & "/" & Ada.Directories.Simple_Name (Ada.Command_Line.Command_Name) & Getpid'Img);
P.Start;
C.Set_Handler (A'Unchecked_Access);
C.Connect ("mqtt");
C.Connect (Host => "mqtt", Keepalive => 30.0);
C.Subscribe (Topic => "#");
C.Publish (Mid => null, Topic => "test", Payload => "[" & GNAT.Time_Stamp.Current_Time & "] Hej", Qos => QOS_0, Retain => False);
delay 1.0;
Expand Down

0 comments on commit 640e315

Please sign in to comment.