From owner-freebsd-net@FreeBSD.ORG Wed Oct 20 19:51:39 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BC80716A4CE for ; Wed, 20 Oct 2004 19:51:39 +0000 (GMT) Received: from park.rambler.ru (park.rambler.ru [81.19.64.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5D6DF43D60 for ; Wed, 20 Oct 2004 19:51:38 +0000 (GMT) (envelope-from is@rambler-co.ru) Received: from is.park.rambler.ru (is.park.rambler.ru [81.19.64.102]) by park.rambler.ru (8.12.6/8.12.6) with ESMTP id i9KJpais056528; Wed, 20 Oct 2004 23:51:36 +0400 (MSD) (envelope-from is@rambler-co.ru) Date: Wed, 20 Oct 2004 23:51:36 +0400 (MSD) From: Igor Sysoev X-X-Sender: is@is.park.rambler.ru To: "Ronald F. Guilmette" In-Reply-To: <49035.1098044385@monkeys.com> Message-ID: <20041020233952.V17688@is.park.rambler.ru> References: <49035.1098044385@monkeys.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-net@freebsd.org Subject: Re: aio_connect ? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Oct 2004 19:51:39 -0000 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/