comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Lundin" <b.f.lundin@gmail.com>
Subject: Re: alternative for buggy accept_socket to create a non-blocking version
Date: Fri, 27 Oct 2017 11:14:31 +0200
Date: 2017-10-27T11:14:31+02:00	[thread overview]
Message-ID: <osutdn$ha8$1@dont-email.me> (raw)
In-Reply-To: <fde3b429-3d55-4dbf-8183-d6ffc5137e01@googlegroups.com>

On 2017-10-25 19:23, Matt Borchers wrote:

> Does anybody know of a good way to create a type of non-blocking accept_socket?

put the socket in select (the socket function - not tasking) with a
timeout of 2 secs (in the readable set)
if select times out, you get 0 as retrun value,
 if select returns > 0 you have someone trying to connect.
You can then call accept and know it will not be blocking.

You may have to pragma import select
(And I hope it works with gnat.sockets)

looking into
<https://www2.adacore.com/gap-static/GNAT_Book/html/rts/g-socket__ads.htm>

  procedure Check_Selector

seem to be exactly this



> 
> My code basically is:
> 
> with GNAT.Sockets; use GNAT.Sockets;
> ...
> declare
>   sock,
>   socket   : SOCKET_TYPE;
>   address  : SOCK_ADDR_TYPE;
>   data     : STREAM_ELEMENT_ARRAY(1..256);
>   last     : STREAM_ELEMENT_OFFSET;
>   sel_stat : SELECTOR_STATUS;
> begin
>   create_socket( socket );
>   bind_socket( socket, address );
>   listen_socket( socket );
>   accept_socket( socket, sock, address );
>   --I wish I could do this
>   --accept_socket( socket, sock, address, timeout => 2.0, status => sel_stat );
>   ...
>   loop
>     receive_socket( sock, data, last );
>     ...
>   end loop;
>   close_socket( socket );
> end;
> 
> Thanks,
> Matt
> 


-- 
--
Björn

  parent reply	other threads:[~2017-10-27  9:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-25 17:23 alternative for buggy accept_socket to create a non-blocking version Matt Borchers
2017-10-25 19:14 ` Matt Borchers
2017-10-26 13:43   ` Shark8
2017-10-25 19:18 ` Dmitry A. Kazakov
2017-10-27  9:14 ` Björn Lundin [this message]
2017-10-27 23:46   ` Matt Borchers
2017-10-27 16:26 ` Daniel Norte Moraes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox