* Florist Generic_Shared_Memory problem
@ 2004-06-28 9:16 Lionel.DRAGHI
0 siblings, 0 replies; only message in thread
From: Lionel.DRAGHI @ 2004-06-28 9:16 UTC (permalink / raw)
To: comp.lang.ada
I am trying to use the POSIX.Generic_Shared_Memory package.
Here is a small test with a server writting random data in a shared memory,
and a client reading those data.
I got the same behavior on both Linux Debian (GNAT 3.15p) and Solaris 2.8
(GNAT 5.03w):
the server runs OK, but the client raise a Storage_Error on the
Access_Shared_Memory call.
Any hints?
Thanks in advance.
--
Lionel Draghi http://webshop.ffii.org/
with POSIX.Generic_Shared_Memory;
package Common_Definitions is
Memory_Name : constant POSIX.POSIX_String :=
POSIX.To_POSIX_String (String'('/' & "Mem"));
-- for portability, should :
-- - start with '/'
-- - contain no other '/'
-- - being 14 Character long Max
type Colour is (Red, Green, Blue);
type Count is range 0 .. 255;
type Data is record
The_Colour : Colour;
The_Count : Count;
end record;
function Image (The_Data : in Data) return String;
package Shared_Memory is new POSIX.Generic_Shared_Memory (Data);
end Common_Definitions;
package body Common_Definitions is
function Image (The_Data : in Data) return String is
begin
return "["
& Common_Definitions.Colour'Image (The_Data.The_Colour)
& ","
& Common_Definitions.Count'Image (The_Data.The_Count)
&"]";
end Image;
end Common_Definitions;
with POSIX.IO;
with POSIX.Memory_Mapping;
with Common_Definitions;
procedure Client is
File : POSIX.IO.File_Descriptor;
use Common_Definitions;
begin
File := Shared_Memory.Open_And_Map_Shared_Memory
(Name => Common_Definitions.Memory_Name,
Protection => POSIX.Memory_Mapping.Allow_Write);
Monitoring : loop
declare
Current_Data : constant Common_Definitions.Data :=
Shared_Memory.Access_Shared_Memory (File).all;
begin
Ada.Text_IO.Put_Line
("Client : reading " & Image (Current_Data));
delay (1.0);
end;
end loop Monitoring;
end Client;
with Ada.Text_IO;
with POSIX.IO;
with POSIX.Memory_Mapping;
with POSIX.Permissions;
with POSIX.Shared_Memory_Objects;
with Common_Definitions;
procedure Server is
package Ramdom_Colour is
new Ada.Numerics.Discrete_Random (Common_Definitions.Colour);
package Ramdom_Count is
new Ada.Numerics.Discrete_Random (Common_Definitions.Count);
G1 : Ramdom_Colour.Generator;
G2 : Ramdom_Count.Generator;
File : POSIX.IO.File_Descriptor;
use Common_Definitions;
begin
File := Shared_Memory.Open_Or_Create_And_Map_Shared_Memory
(Name => Common_Definitions.Memory_Name,
Protection => POSIX.Memory_Mapping.Allow_Write,
Permissions => POSIX.Permissions.Owner_Permission_Set);
Data_Update : loop
declare
New_Data : constant Data :=
(The_Colour => Ramdom_Colour.Random (G1),
The_Count => Ramdom_Count.Random (G2));
begin
-- Shared_Memory.Lock_Shared_Memory (File);
Shared_Memory.Access_Shared_Memory (File).all := New_Data;
-- Shared_Memory.Unlock_Shared_Memory (File);
Ada.Text_IO.Put_Line
("Server : written "
& Image (Shared_Memory.Access_Shared_Memory (File).all));
delay (1.0);
end;
end loop Data_Update;
Shared_Memory.Unmap_And_Close_Shared_Memory (File);
POSIX.Shared_Memory_Objects.Unlink_Shared_Memory
(Common_Definitions.Memory_Name);
end Server;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2004-06-28 9:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-28 9:16 Florist Generic_Shared_Memory problem Lionel.DRAGHI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox