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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news3.google.com!feeder.news-service.com!news2.euro.net!newsfeed.freenet.de!news.teledata-fn.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Aborting a call to Accept_Socket Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <44d6b044-3cb8-402c-9b1f-afe39f6a47ce@r33g2000yqn.googlegroups.com> Date: Tue, 21 Apr 2009 18:21:57 +0200 Message-ID: <5v74txgo3q9d$.cj2k983k72sh$.dlg@40tude.net> NNTP-Posting-Date: 21 Apr 2009 18:21:59 CEST NNTP-Posting-Host: 5b9f7a51.newsspool2.arcor-online.net X-Trace: DXC=aeW_QfA5K1iUoRk[hk2WalA9EHlD;3Ycb4Fo<]lROoRa^YC2XCjHcbicCT 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. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de