On Mon, Nov 01, 2004 at 03:42:52AM -0600, Mike Silbersack wrote: > > 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.
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). -- 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
pgpVo3CIdFDPV.pgp
Description: PGP signature