From owner-freebsd-net@FreeBSD.ORG Fri Oct 29 20:45:16 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 0D8B616A4CE for ; Fri, 29 Oct 2004 20:45:16 +0000 (GMT) Received: from mail.vicor-nb.com (bigwoop.vicor-nb.com [208.206.78.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id E9EAE43D2F for ; Fri, 29 Oct 2004 20:45:15 +0000 (GMT) (envelope-from julian@elischer.org) Received: from elischer.org (julian.vicor-nb.com [208.206.78.97]) by mail.vicor-nb.com (Postfix) with ESMTP id D44187A403; Fri, 29 Oct 2004 13:45:15 -0700 (PDT) Message-ID: <4182ABDB.7040104@elischer.org> Date: Fri, 29 Oct 2004 13:45:15 -0700 From: Julian Elischer User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.3.1) Gecko/20030516 X-Accept-Language: en, hu MIME-Version: 1.0 To: Ollie Cook References: <20041029123506.GG19662@mutare.noc.clara.net> In-Reply-To: <20041029123506.GG19662@mutare.noc.clara.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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: Fri, 29 Oct 2004 20:45:16 -0000 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). > >At the moment this is implemented as follows (in pseudo-C; no error-checking >for brevity and clarity): > > written_bytes = 0; > read_bytes = read(sock_src, buffer, sz_buffer); > while (written_bytes < read_bytes) > written_bytes -= write(sock_dst, buffer, read_bytes - written_bytes) > >I am wondering if there is a more efficient approach to this which might avoid >copying data into a userspace buffer, and then writing it back to the kernel? > you can do it entirely in the kernel if you write a program to configure two netgraph ksockets to each other > >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. > >Yours, > >Ollie > > >