On Wed, Apr 18, 2001 at 11:31:00PM +0200, Andi Kleen wrote:
> On Thu, Apr 19, 2001 at 12:28:52AM +0200, Joel Eriksson wrote:
> > Hello,
> >
> > I am a kernel hacking newbie and am struggling to understand the
> > networking subsystem. I would like to be able to add a systemcall,
> > preferably asynchronous, that connects a socket with a filedescriptor
> > (proxy(srcsd, dstfd)) so that everything received on srcsd is directly
> > written to dstfd. The proxy should close when srcsd is closed or when
> > a zero-size packet is sent (or something like that..).
>
> That syscall already exists -- it's called sendfile.
Actually, I realised the similarities with sendfile() after I made the
post. :-) But I thought sendfile() could only be used for sending data
from a "regular" file descriptor to another file- or socket descriptor..?
The syscall I would like to implement is kind of the reverse to sendfile()
since it should be used to copy data _from_ a socket descriptor to a
file descriptor.
Hmm, I made a small test program and from what I can understand it seems
to verify what I thought:
--- #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> #include <errno.h> #include <stdio.h>int main(void) { pid_t pid; int fdarr[2];
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fdarr) ˙-1) { perror("socketpair"); return 1; }
if ((pid ˙ork()) ˙-1) { perror("fork"); return 1; } else if (pid) { close(fdarr[0]); if (sendfile(1, fdarr[1], NULL, 5) ˙-1) { perror("sendfile"); return 1; } } else { close(fdarr[1]); write(fdarr[0], "Test\n", 5); }
return 0; } ---
The output from the program is "sendfile: Invalid argument"..
> -Andi
-- Joel Eriksson - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Mon Apr 23 2001 - 21:00:29 EST