Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Oct 2004 23:51:36 +0400 (MSD)
From:      Igor Sysoev <is@rambler-co.ru>
To:        "Ronald F. Guilmette" <rfg@monkeys.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: aio_connect ?
Message-ID:  <20041020233952.V17688@is.park.rambler.ru>
In-Reply-To: <49035.1098044385@monkeys.com>
References:  <49035.1098044385@monkeys.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 17 Oct 2004, Ronald F. Guilmette wrote:

> I'm sitting here looking at that man pages for aio_read and aio_write,
> and the question occurs to me:  ``Home come there is no such thing as
> an aio_connect function?''
>
> There are clearly cases in which one would like to perform reads
> asynchronously, but likewise, there are cases where one might like
> to also perform socket connects asynchronously.  So how come no
> aio_connect?

In FreeBSD you can do connect() on the non-blocking socket, then set
the socket to a blocking mode, and post aio_read() or aio_write()
operations on the socket.

FreeBSD allows to post AIO operaitons on non-connected socket.
NT (and W2K, I believe) do not. This is why ConnectEx() appeared in XP.
I do not know about other OSes, but I belive only FreeBSD and NT have
the kernel level AIO sockets implementation without the threads emulation
in the user level (Solaris) or without the quietly falling to synchronous
behaviour (Linux).

While the developing my server nginx, I found the POSIX aio_* operations
uncomfortable. I do not mean a different programming style, I mean
the aio_read() and aio_write() drawbacks - they have no scatter-gather
capabilities (aio_readv/aio_writev) and they require too many syscalls.
E.g, the reading requires
*) 3 syscalls for ready data: aio_read(), aio_error(), aio_return()
*) 5 syscalls for non-ready data: aio_read(), aio_error(),
   waiting for notification, then aio_error(), aio_return(),
   or if timeout occuired - aio_cancel(), aio_error().

I think aio_* may be usefull for the zero-copy sockets, however,
FreeBSD's aio_write() does not wait when the data would be acknowledged
by peer and notifies the completion just after it pass the data to
the network layer.


Igor Sysoev
http://sysoev.ru/en/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041020233952.V17688>