Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect passing of keepalive values #3

Merged
merged 2 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Next Next commit
Fix incorrect passing of keepalive values
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 #1.
  • Loading branch information
mgrojo committed Dec 11, 2021
commit 640e315c09c1777ca6e3e21f1511653ba0b4ea7e
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