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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f7061427cd055975 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "mferracini" Newsgroups: comp.lang.ada Subject: Re: Using Check_Selector ... Date: 1 Mar 2005 03:25:12 -0800 Organization: http://groups.google.com Message-ID: <1109676312.473031.46240@f14g2000cwb.googlegroups.com> References: <1109674151.141839.96860@l41g2000cwc.googlegroups.com> NNTP-Posting-Host: 213.215.153.30 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1109676316 2860 127.0.0.1 (1 Mar 2005 11:25:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 1 Mar 2005 11:25:16 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=213.215.153.30; posting-account=OjhBzA0AAAC7IWpsLrvIpzjmXdzmh93y Xref: g2news1.google.com comp.lang.ada:8564 Date: 2005-03-01T03:25:12-08:00 List-Id: Duncan Sands wrote: > You should do this "Set (Rset, ...)" every time around the loop (and > clear the write set). After all, if the selector times out the > Rset will be empty, and then you loop around and check the > selector with an empty Rset... ^_^ perfect now work fine, i post the source code for who have similar problem. Maurizio ------------------------------------------------------------------------------- with Gnat.Sockets;use Gnat.Sockets; with Ada.Exceptions;use Ada.Exceptions; with Ada.Streams; with Ada.Text_Io; procedure server is Selector : Selector_Type; Rset, Wset : Socket_Set_Type; Status : Selector_Status; task Pong is entry Start; end Pong; task body Pong is Address : Sock_Addr_Type; Server : Socket_Type; Socket : Socket_Type; begin accept Start; Address.Addr := Addresses (Get_Host_By_Name (Host_Name), 1); Address.Port := 31337; Create_Socket (Server); Ada.Text_Io.Put_Line("In attesa di connessione"); -- Allow reuse of local addresses. Set_Socket_Option (Server, Socket_Level, (Reuse_Address, True)); Bind_Socket (Server, Address); Listen_Socket (Server); Empty(Rset); Empty(Wset); Accept_Socket (Server, Socket, Address); Ada.Text_Io.Put_Line ("nuova connessione"); -- crea selector Set(Rset, Socket); Create_Selector(Selector); declare Message : Ada.Streams.Stream_Element_Array (1 .. 300); Last : Ada.Streams.Stream_Element_Offset; begin loop Check_Selector(Selector, Rset, Wset, Status, 0.0); if (Status /= Expired ) then Receive_Socket(Socket,Message,Last); Ada.Text_Io.Put_Line("letto"); else Ada.Text_Io.Put(Selector_Status'Image(Status)&" "); end if; Set(Rset, Socket); end loop; end; exception when E : others => Ada.Text_Io.Put_Line (Exception_Name (E) & ": " & Exception_Message (E)); end Pong; begin Initialize (Process_Blocking_Io => False); Pong.Start; end server; -------------------------------------------------------------------------------- with Gnat.Sockets;use Gnat.Sockets; with Ada.Streams; with Ada.Text_Io; with Ada.Integer_Text_Io; procedure Client is Server : Sock_Addr_Type; Config : Ada.Text_Io.File_Type; Host : String (1 .. 20) := (others => ' '); Port_Value : String (1 .. 20) := (others => ' '); Last : Natural := 0; Handle : Socket_Type; Buffer : Ada.Streams.Stream_Element_Array (1 .. 80); Sk_Last : Ada.Streams.Stream_Element_Offset; begin --Inizializza --leggi da config Initialize(True); --true?? Ada.Text_Io.Open( File => Config, Mode => Ada.Text_Io.In_File, Name => "config.ini"); --case sensitive? Ada.Text_Io.Get_Line( File => Config, Item => Host, Last => Last); Server.Addr := Addresses(Get_Host_By_Name( Host( 1 .. Last ) ) ); Ada.Text_Io.Get_Line( File => Config, Item => Port_Value, Last => Last); Ada.Integer_Text_Io.Get(Port_Value,Natural(Server.Port),Last); Ada.Text_Io.Put_Line(Item => "TCP/IP Host: " & Host & "Porta:" & Port_Type'Image (Server.Port)); --apri la socket Create_Socket (Handle, Family_Inet, Socket_Stream); Set_Socket_Option(Handle, Socket_Level, (Reuse_Address, True)); Connect_Socket (Handle, Server); Ada.Text_Io.Put_Line("Connesso"); loop Buffer(1):=42; Send_Socket(Handle,Buffer,Sk_Last); Ada.Text_Io.Put_Line("->write something"); delay(1.0); end loop; end Client; ------------------------------------------------------------------------------- the file config.ini is -- localhost 31337 ---