From owner-freebsd-net@FreeBSD.ORG Mon Nov 1 10:06:38 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 0242416A4CE for ; Mon, 1 Nov 2004 10:06:38 +0000 (GMT) Received: from odin.ac.hmc.edu (Odin.AC.HMC.Edu [134.173.32.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id C621143D31 for ; Mon, 1 Nov 2004 10:06:37 +0000 (GMT) (envelope-from brdavis@odin.ac.hmc.edu) Received: from odin.ac.hmc.edu (localhost.localdomain [127.0.0.1]) by odin.ac.hmc.edu (8.13.0/8.13.0) with ESMTP id iA1A6fWd017464; Mon, 1 Nov 2004 02:06:41 -0800 Received: (from brdavis@localhost) by odin.ac.hmc.edu (8.13.0/8.13.0/Submit) id iA1A6f6V017463; Mon, 1 Nov 2004 02:06:41 -0800 Date: Mon, 1 Nov 2004 02:06:41 -0800 From: Brooks Davis To: Mike Silbersack Message-ID: <20041101100641.GB13309@odin.ac.hmc.edu> References: <20041029123506.GG19662@mutare.noc.clara.net> <20041101033406.A37052@odysseus.silby.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="2B/JsCI69OhZNC5r" Content-Disposition: inline In-Reply-To: <20041101033406.A37052@odysseus.silby.com> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new X-Spam-Status: No, hits=0.0 required=8.0 tests=none autolearn=no version=2.63 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on odin.ac.hmc.edu cc: Ollie Cook 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 10:06:38 -0000 --2B/JsCI69OhZNC5r Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 01, 2004 at 03:42:52AM -0600, Mike Silbersack wrote: >=20 > On Fri, 29 Oct 2004, Ollie Cook wrote: >=20 > >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= =20 > >reason > >it has to be PF_INET, but that's how the application stands). >=20 > >In actual fact, I know in advance exactly how many bytes need to be copi= ed=20 > >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 t= o=20 > >do > >that did actually exist. > > > >If anyone has any advice at all on a more efficient way to copy data=20 > >between > >sockets I'd be very glad to hear about it. The software is very much=20 > >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. >=20 > Splicing bytes from one socket's buffer to another socket's buffer should= =20 > be relatively simple to do inside the kernel, but I don't think it's=20 > implemented anywhere at this point in time. >=20 > If you're really need that functionality, the best place to do it would= =20 > probably be in sendfile; you could just extend it so that if two sockets= =20 > are passed to it instead of a socket and file, it would do what you've=20 > described above. I've thought about this on and off and think there's a good case for such a service, however, the sendfile API is a bit too focused for some of things you might want to do. I would encourage any intrested person to do a socket->socket or file->file version[0] with sendfile since it's already there and both cases would be useful, but I think an API that allows you to specify multiple pairs is necessicary in the general case. Think of netcat where you want to hook stdin and stdout to a socket. -- Brooks [0] think cp(1) in five syscalls (open, open, sendfile, close, close). --=20 Any statement of the form "X is the one, true Y" is FALSE. PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 --2B/JsCI69OhZNC5r Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQFBhgqwXY6L6fI4GtQRAi5GAJ91L7zIUjTJ5eFeI89inv3PECyQdACfd6C5 3tuIB4/TIdLbpAI2xAJisMc= =sAXS -----END PGP SIGNATURE----- --2B/JsCI69OhZNC5r--