Re: Efficient copying between sockets

From: Julian Elischer (julian_at_elischer.org)
Date: 10/29/04

  • Next message: Ari Suutari: "ipfw and ipsec processing order for outgoing packets wrong"
    Date: Fri, 29 Oct 2004 13:45:15 -0700
    To: Ollie Cook <ollie@uk.clara.net>
    
    

    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
    >
    >
    >

    _______________________________________________
    freebsd-net@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-net
    To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"


  • Next message: Ari Suutari: "ipfw and ipsec processing order for outgoing packets wrong"

    Relevant Pages

    • Re: [PATCH 2.6.15.4 1/1][RFC] ipt_owner: inode match supporting both incoming and outgoing packets
      ... I didn't say there wasn't a reason for it going away. ... Is the sk_sleep field of struct socket going to remain? ... Then I could do the rest of the checking in userspace. ... This is my first attempt at modifying the kernel. ...
      (Linux-Kernel)
    • Re: Socket recv() question?
      ... You might be doing something crazy, writing the data to the file one byte at ... socket function correctly? ... How come when I use the IE on the Pocket PC and started IIS on my PC. ... Configure tx timeout ...
      (microsoft.public.windowsce.app.development)
    • Re: Are write() calls guaranteed atomic?
      ... >> writing the data have no knowledge of the FIFO, ... > If you cannot modify the clients, try changing your server to create a ... > Unix domain socket instead of a named pipe (the clients shouldn't see ...
      (freebsd-hackers)
    • Re: C++ problem with a destructor
      ... > and write a data file to the file ... > descriptor (socket). ... > because, for kicks and grins, I tried writing a simple program to test ... add a private copy constructor and assignment operator and ...
      (alt.comp.lang.learn.c-cpp)
    • Re: Tivo Program Data IP Address
      ... connecting to 204.176.49.3:80 ... writing 364 bytes to socket ... select-ing for header ...
      (uk.tech.tv.video.pvr)