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.4 required=5.0 tests=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2afbf99c1f65cbe X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.180.88.195 with SMTP id bi3mr1185600wib.3.1344263635864; Mon, 06 Aug 2012 07:33:55 -0700 (PDT) Path: q11ni72544147wiw.1!nntp.google.com!feed-C.news.volia.net!volia.net!news2.volia.net!feed-A.news.volia.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.panservice.it!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Sharing a socket connection Date: Tue, 31 Jul 2012 13:18:50 +0300 Organization: Tidorum Ltd Message-ID: References: <87hasofgwa.fsf@adaheads.sparre-andersen.dk> Mime-Version: 1.0 X-Trace: individual.net Jp+BHzhE18Au/+GtBUCNnAFuxbDkTj4slNwagRwa/wI3TLXy1a5k02dpzr34qvCFBZ Cancel-Lock: sha1:RSH2KBd8yyIAlr4BaBZpJI3BcLE= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <87hasofgwa.fsf@adaheads.sparre-andersen.dk> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2012-07-31T13:18:50+03:00 List-Id: On 12-07-31 11:56 , Jacob Sparre Andersen wrote: > We are working on a system where a number of Ada tasks are going to > share a single socket connection to a server [1]. > > The socket connection is bidirectional with requests sent from a client > followed by corresponding responses from the server. Each client should > only get responses to its own requests. > > Our current approach is to encapsulate the socket in a package, and use > a mutex [2] to lock the socket during an entire > send-request-get-response operation. Why not use a "server" task inside the package, with rendez-vous in the classical Ada style? The "server" task has a single entry, which has an "in" parameter for the request from a client task and an "out" parameter for the response. The accept statement for the entry sends the request over the socket, waits for the response, and returns the response in the "out" parameter. The "server" task body looks like this: loop accept The_Entry (Request, Response) do Socket_Send (Request); Socket_Receive (Response); end The_Entry; end loop; This provides mutual exclusion between the client tasks within the accept body, without the need for an explicit mutex. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .