* alternative for buggy accept_socket to create a non-blocking version
@ 2017-10-25 17:23 Matt Borchers
2017-10-25 19:14 ` Matt Borchers
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Matt Borchers @ 2017-10-25 17:23 UTC (permalink / raw)
I have no choice but to use an old GNAT compiler -- version 6.3.0. In this version there is a confirmed bug (fixed in 6.3.2) that prevents the non-blocking version of accept_socket from working. I want to call the version of accept_socket with the 'timeout' parameter, but it doesn't do what it should.
Basically, I've built a way to read data from a socket and all goes well when a response is made. However, I need a way to abandon the accept call if a response is never sent within a small time window.
This is my foray into sockets programming and I don't fully understand all of the nuances yet. I tried setting the Receive_Timeout socket option but it had no effect -- I don't think it does what I need anyway. This all seems pretty straight-forward assuming there is no bug in the non-blocking version of accept_socket, but I don't know how to work-around this bug.
I can imagine a pair of tasks in which one does the blocking accept (A) and the other task (B) does the time-out. If the time-out occurs first, B will abort the task A otherwise after A succeeds in accepting the message it will abort B. This seems like it might not be the best work-around solution.
Does anybody know of a good way to create a type of non-blocking accept_socket?
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alternative for buggy accept_socket to create a non-blocking version
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
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Matt Borchers @ 2017-10-25 19:14 UTC (permalink / raw)
Well, I should have thought of this solution sooner. I downloaded the GNAT 6.3.2 version (where the bug is fixed) and I copied all of the execution path of the non-blocking accept_socket subprogram into a single subroutine in a new child package of GNAT.Sockets.
My first few tests are successful.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alternative for buggy accept_socket to create a non-blocking version
2017-10-25 19:14 ` Matt Borchers
@ 2017-10-26 13:43 ` Shark8
0 siblings, 0 replies; 7+ messages in thread
From: Shark8 @ 2017-10-26 13:43 UTC (permalink / raw)
On Wednesday, October 25, 2017 at 1:14:47 PM UTC-6, Matt Borchers wrote:
> Well, I should have thought of this solution sooner. I downloaded the GNAT 6.3.2 version (where the bug is fixed) and I copied all of the execution path of the non-blocking accept_socket subprogram into a single subroutine in a new child package of GNAT.Sockets.
>
> My first few tests are successful.
You could try using a Generic Package taking a TIMEOUT formal parameter (and if you're using task-interfaces, an interface to your socket-task) then simply have one task do your processing and the other send an abort to the other task if/when the timeout occurs.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alternative for buggy accept_socket to create a non-blocking version
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-25 19:18 ` Dmitry A. Kazakov
2017-10-27 9:14 ` Björn Lundin
2017-10-27 16:26 ` Daniel Norte Moraes
3 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2017-10-25 19:18 UTC (permalink / raw)
On 2017-10-25 19:23, Matt Borchers wrote:
> I have no choice but to use an old GNAT compiler -- version 6.3.0.
> In this version there is a confirmed bug (fixed in 6.3.2) that prevents the
> non-blocking version of accept_socket from working.
Never had problems with that.
> Does anybody know of a good way to create a type of non-blocking
> accept_socket?
Set Receive_Timeout?
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alternative for buggy accept_socket to create a non-blocking version
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-25 19:18 ` Dmitry A. Kazakov
@ 2017-10-27 9:14 ` Björn Lundin
2017-10-27 23:46 ` Matt Borchers
2017-10-27 16:26 ` Daniel Norte Moraes
3 siblings, 1 reply; 7+ messages in thread
From: Björn Lundin @ 2017-10-27 9:14 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: alternative for buggy accept_socket to create a non-blocking version
2017-10-25 17:23 alternative for buggy accept_socket to create a non-blocking version Matt Borchers
` (2 preceding siblings ...)
2017-10-27 9:14 ` Björn Lundin
@ 2017-10-27 16:26 ` Daniel Norte Moraes
3 siblings, 0 replies; 7+ messages in thread
From: Daniel Norte Moraes @ 2017-10-27 16:26 UTC (permalink / raw)
Em quarta-feira, 25 de outubro de 2017 15:23:52 UTC-2, Matt Borchers escreveu:
> I have no choice but to use an old GNAT compiler -- version 6.3.0. In this version there is a confirmed bug (fixed in 6.3.2) that prevents the non-blocking version of accept_socket from working. I want to call the version of accept_socket with the 'timeout' parameter, but it doesn't do what it should.
>
> Basically, I've built a way to read data from a socket and all goes well when a response is made. However, I need a way to abandon the accept call if a response is never sent within a small time window.
>
> This is my foray into sockets programming and I don't fully understand all of the nuances yet. I tried setting the Receive_Timeout socket option but it had no effect -- I don't think it does what I need anyway. This all seems pretty straight-forward assuming there is no bug in the non-blocking version of accept_socket, but I don't know how to work-around this bug.
>
> I can imagine a pair of tasks in which one does the blocking accept (A) and the other task (B) does the time-out. If the time-out occurs first, B will abort the task A otherwise after A succeeds in accepting the message it will abort B. This seems like it might not be the best work-around solution.
>
> Does anybody know of a good way to create a type of non-blocking accept_socket?
>
> 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
Or you can use lib Anet.
[]'s Dani.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-10-27 23:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2017-10-27 23:46 ` Matt Borchers
2017-10-27 16:26 ` Daniel Norte Moraes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox