From: Eric Dumazet <eric.dumazet@gmail.com>
To: Viral Mehta <Viral.Mehta@lntinfotech.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: zero copy for relay server
Date: Mon, 28 Mar 2011 18:52:18 +0200 [thread overview]
Message-ID: <1301331138.3182.43.camel@edumazet-laptop> (raw)
In-Reply-To: <D69C90565D53114396BF743585AF5A09122E61E9E7@VSHINMSMBX01.vshodc.lntinfotech.com>
Le lundi 28 mars 2011 à 21:57 +0530, Viral Mehta a écrit :
> Hi,
> I am implementing a particular application where
> my application acts nothing but like Relay Server.
>
> Relay server accepts connection from machine A.
> It also accepts connection from Machine B.
>
> Machine A and B are on different LAN/subnnets.
> Now, there are two connections.
> What server is supposed to do is RECV packets from machine A and SEND same
> to machine B.
>
> Pseudo Code is something like,
> while(1)
> {
> recvagain:
> n =3D recv(incoming_fd, &buf, 8192, ...)
> if(n < 0)
> goto recvagain;
> send(outgoing_fd, &buf, n, ...);
> }
>
> Now the question is,
> I want to avoid kernel-user copy for such application.
> I found that a syscall like "sendfile"; I wanted to know if there is any
> similar thing exists in-kernel which can take 2 socket descriptors....
>
> If not, is it possible ? I would like to implement the same if someone
> can suggest some pointers.
linux way (if you want to avoid netfilter stuff and use userland code)
is to use splice() system call, and a pipe between two sockets.
/* skeleton : must add error checking to exit the loop properly */
int fds[2];
pipe(fds);
while (1) {
splice(incoming_fd, NULL, fds[1], NULL, 65536, 0);
splice(fds[0], NULL, outgoing_fd, NULL, 65536, 0);
}
This way, messages dont cross kernel<>user boundary.
The pipe is acting as a buffer between the two sockets.
next prev parent reply other threads:[~2011-03-28 16:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-28 16:27 zero copy for relay server Viral Mehta
2011-03-28 16:52 ` Eric Dumazet [this message]
2011-03-28 18:18 ` Viral Mehta
2011-03-28 18:34 ` Eric Dumazet
2011-03-29 2:00 ` Changli Gao
2011-03-29 4:23 ` Eric Dumazet
2011-03-29 11:28 ` Changli Gao
2011-03-29 14:13 ` Eric Dumazet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1301331138.3182.43.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=Viral.Mehta@lntinfotech.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox