From owner-freebsd-net@FreeBSD.ORG Mon Nov 1 09:42:56 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 BA87C16A4CE for ; Mon, 1 Nov 2004 09:42:56 +0000 (GMT) Received: from relay03.pair.com (relay03.pair.com [209.68.5.17]) by mx1.FreeBSD.org (Postfix) with SMTP id 1AE6843D49 for ; Mon, 1 Nov 2004 09:42:56 +0000 (GMT) (envelope-from silby@silby.com) Received: (qmail 53596 invoked from network); 1 Nov 2004 09:42:53 -0000 Received: from niwun.pair.com (HELO localhost) (209.68.2.70) by relay03.pair.com with SMTP; 1 Nov 2004 09:42:53 -0000 X-pair-Authenticated: 209.68.2.70 Date: Mon, 1 Nov 2004 03:42:52 -0600 (CST) From: Mike Silbersack To: Ollie Cook In-Reply-To: <20041029123506.GG19662@mutare.noc.clara.net> Message-ID: <20041101033406.A37052@odysseus.silby.com> References: <20041029123506.GG19662@mutare.noc.clara.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed cc: freebsd-net@freebsd.org Subject: Re: Efficient copying between sockets 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: Mon, 01 Nov 2004 09:42:56 -0000 On Fri, 29 Oct 2004, Ollie Cook wrote: > Good afternoon, > > I am currently writing a potentially high bandwidth (think fileserver) > application which will proxy data from one PF_INET socket to another (no reason > it has to be PF_INET, but that's how the application stands). > In actual fact, I know in advance exactly how many bytes need to be copied from > one socket to the other, so if there was any way of doing something like: > > socket_redirect(sock_src, sock_dst, bytes_to_copy); > > it would be ideal. However I'd be very surprised if such a trivial way to do > that did actually exist. > > If anyone has any advice at all on a more efficient way to copy data between > sockets I'd be very glad to hear about it. The software is very much prototype > at the moment, but I'd like to make it as efficient as possible from the > beginning and this seems like a prime area for optimisation. Splicing bytes from one socket's buffer to another socket's buffer should be relatively simple to do inside the kernel, but I don't think it's implemented anywhere at this point in time. If you're really need that functionality, the best place to do it would probably be in sendfile; you could just extend it so that if two sockets are passed to it instead of a socket and file, it would do what you've described above. Tell us how it works out. :) Mike "Silby" Silbersack