RE: zero copy for relay server
From: Viral Mehta <hidden>
Date: 2011-03-28 18:18:37
From: Eric Dumazet [eric.dumazet@gmail.com]
Le lundi 28 mars 2011 à 21:57 +0530, Viral Mehta a écrit :quoted
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.
Yes, I want to avoid netfilter stuff. I know it but I think it is more complicated than an application programmer should know.
/* 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);
}
Still, these are two system calls.
In addition to this, many things to handle,
1. if the incoming_fd is blocking, then it will block till 64K data read. Why so ?
2. I believe underlying PIPE that we are using will also have some size limit
(like in user space 4K or 64K, not sure)
So, all in all
Why cant we have just one system call which really transfers "length"
bytes of data form one socket to another ? Recv "length" bytes of data
from socket A and send to socket B.
I wanted to understand if there are any limitations or concerns that we still do
not have any such system call .... ?
This way, messages dont cross kernel<>user boundary.
The pipe is acting as a buffer between the two sockets.
______________________________________________________________________ The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s). Unintended recipients are prohibited from taking action on the basis of information in this e-mail and using or disseminating the information, and must notify the sender and delete it from their system. L&T Infotech will not accept responsibility or liability for the accuracy or completeness of, or the presence of any virus or disabling code in this e-mail" ______________________________________________________________________