File: neat_sockets.ads
Documentation Table of Contents Class Inheritance Tree -- -- Uwe R. Zimmer, Australia 2015 -- with GNAT.Sockets; use GNAT.Sockets; package Neat_Sockets To API doc To body is ----------------------------------------------------------------------------- -- -- Usage pattern server-side: -- ----------------------------------------------------------------------------- -- -- declare -- Server_Socket : constant Socket_Type := Open_Server_Port (Port => 60043); -- -- Connection_Socket : Socket_Type; -- Connection_Address : Sock_Addr_Type; -- -- Channel : constant Stream_Access := -- Accept_Connection (Server_Socket, Connection_Socket, Connection_Address); -- -- Message : Message_Type; -- -- begin -- ... -- Message_Type'Read (Channel, Message); -- ... -- Message_Type'Write (Channel, Message); -- ... -- Close_Connection (Connection_Socket); -- Close_Server (Server_Socket); -- end; -- ----------------------------------------------------------------------------- -- -- Usage pattern client-side: -- ----------------------------------------------------------------------------- -- -- declare -- Connection_Socket : Socket_Type; -- Channel : constant Stream_Access := -- Connect (Server_Addr => Inet_Addr ("127.0.0.1"), -- Port => 60043, -- Connection_Socket => Connection_Socket); -- -- Message : Message_Type := 42; -- -- begin -- ... -- Message_Type'Write (Channel, Message); -- ... -- Message_Type'Read (Channel, Message); -- ... -- Close_Socket (Connection_Socket); -- end; -- ----------------------------------------------------------------------------- function Open_Server_Port To API doc To body (Port : Port_Type; Server_Addr To API doc To body : Inet_Addr_Type := Addresses (Get_Host_By_Name (Host_Name))) return Socket_Type; -- Accept_Connection blocks until a connection attempt is made function Accept_Connection To API doc To body (Server_Socket : Socket_Type; Connection_Socket : out Socket_Type; Connection_Address To API doc To body : out Sock_Addr_Type) return Stream_Access; -- Connect tries to connect to server once every 100 ms until it succeeds function Connect To API doc To body (Server_Addr To API doc To body : Inet_Addr_Type; Port : Port_Type; Connection_Socket : out Socket_Type) return Stream_Access; procedure Close_Connection To API doc To body (Connection_Socket : Socket_Type); procedure Close_Server To API doc To body (Server_Socket : Socket_Type); end Neat_Sockets To API doc To spec To body;