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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,61ec2c598155da95 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!v35g2000pro.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Aborting a call to Accept_Socket Date: Tue, 21 Apr 2009 10:34:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: <79d6b179-ae94-4303-a7ed-96a9a6556438@v35g2000pro.googlegroups.com> References: <44d6b044-3cb8-402c-9b1f-afe39f6a47ce@r33g2000yqn.googlegroups.com> <5v74txgo3q9d$.cj2k983k72sh$.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1240335285 13011 127.0.0.1 (21 Apr 2009 17:34:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 21 Apr 2009 17:34:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v35g2000pro.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4547 Date: 2009-04-21T10:34:45-07:00 List-Id: On Apr 21, 9:21 am, "Dmitry A. Kazakov" wrote: > On Tue, 21 Apr 2009 08:40:13 -0700 (PDT), Tony wrote: > > I would like to abort a call to Accept_Socket() if no connection > > request arrives within a specified time (20 seconds). For me, a quite > > simple solution (perhaps not safe) is to use an asynchronous transfer > > of control like this: > > --**************************************************** > > procedure Server is > > ... > > begin > > GNAT.Sockets.Initialize; > > ... > > loop > > ... > > select > > delay 20.0; > > exit; > > then abort > > GNAT.Sockets.Accept_Socket (...); > > end select; > > ... > > end loop ; > > end Server; > > --**************************************************** > > The expecting behaviour was the end of the program after 20 seconds > > (if no connection request arrives). I observe : after 20 seconds the > > program will terminate only if a connection request arrives. > > Is this behaviour correct? > > Yes, it is. Asynchronous transfer of control is not guaranteed to work with > an outstanding calls. Most likely it does not work as in this case. The > behavior is correct because Ada does not know how to abort a socket > operation in order to implement this statement. Ada RM contains a list of > abort deferred things, which includes potentially any call to any external > operation. Specifically for sockets there is a solution: you close the > socket from another task. That will kill accept with an error code. I think you also have to think about what happens to the client when an incoming connection request comes after 19.999999 seconds... It may be too remote a problem to worry about, but in some circumstances it could be important. -- Adam