Boost logo

Boost :

From: Caleb Epstein (caleb.epstein_at_[hidden])
Date: 2005-08-14 09:10:10

On 8/12/05, Christopher Kohlhoff <chris_at_[hidden]> wrote:
> Hi Caleb,
> --- Caleb Epstein <caleb.epstein_at_[hidden]> wrote:
> > Just to clarify one point: asio is portable. It runs on Windows
> > (using I/O completion ports), Linux (via epoll or select), Solaris
> > and
> > *should* work on any other UNIX-like platform that supports
> > select(2).
> > I had to make a couple of very simple changes to get it to compile
> > on
> > OS/X (the gethostby*_r functions don't seem to be available on this
> > platform).
> In fact I have a patch for OS/X which should be in asio 0.3.3. However
> I believe the functions it uses are not guaranteed to be thread-safe
> until 10.4, so you would only be able to use asio in a single-threaded
> program for earlier OS/X releases.

Or you could implement a custom thread-safe implementation of the asio
resolvers that holds a mutex while resolving names on OS/X < 10.4.
Its a pain, and not 100% bulletproof (what if someone links with some
other library that is using gethostby* in another thread?), but its
just about the best you can do given a thread-unaware runtime.

Another approach, which I've used from time to time, is to provide
your own version of the unsafe C runtime functions that hold a mutex
while calling the unsafe C library routine and copy the result into
thread-specific storage and return that pointer. As long as your
implementation gets linked in before the libc version, you've solved
the problem in all cases.

> Basically the approach I have been taking has been to make asio
> portable first (via select) and then to optimise for each platform. For
> example, it theoretically supports implementations that use /dev/poll
> on Solaris and kqueues on on *bsd (including OS/X AFAIK).

Its a very nice library. I commend you on the design and
implementation. Personally, I think this should be proposed as a
Networking library more or less as-is.

Caleb Epstein
caleb dot epstein at gmail dot com

Boost list run by bdawes at, gregod at, cpdaniel at, john at