comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Sharing a socket connection
Date: Tue, 31 Jul 2012 13:18:50 +0300
Date: 2012-07-31T13:18:50+03:00	[thread overview]
Message-ID: <a7ppo7FuhaU1@mid.individual.net> (raw)
In-Reply-To: <87hasofgwa.fsf@adaheads.sparre-andersen.dk>

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
      .      @       .



  reply	other threads:[~2012-08-06 14:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-31  8:56 Sharing a socket connection Jacob Sparre Andersen
2012-07-31 10:18 ` Niklas Holsti [this message]
2012-07-31 10:28 ` Dmitry A. Kazakov
2012-07-31 11:50   ` Jacob Sparre Andersen
2012-07-31 12:09     ` Dmitry A. Kazakov
replies disabled

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