From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1d4d5d976677f1af,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Lionel.DRAGHI@fr.thalesgroup.com Newsgroups: comp.lang.ada Subject: Florist Generic_Shared_Memory problem Date: Mon, 28 Jun 2004 11:16:51 +0200 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: melchior.cuivre.fr.eu.org 1088414286 79432 212.85.156.195 (28 Jun 2004 09:18:06 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Mon, 28 Jun 2004 09:18:06 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: X-Mailer: Internet Mail Service (5.5.2653.19) X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:1965 Date: 2004-06-28T11:16:51+02:00 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;