public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: Socket hack question.
@ 2001-04-19  1:03 Joel Eriksson
       [not found] ` <Pine.LNX.4.10.10104181931310.14361-100000@coffee.psychology.mcmaster.ca>
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Eriksson @ 2001-04-19  1:03 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Socket hack question.
@ 2001-04-18 22:28 Joel Eriksson
  2001-04-18 21:31 ` Andi Kleen
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Eriksson @ 2001-04-18 22:28 UTC (permalink / raw)
  To: linux-kernel

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

I started digging in the source yesterday, and have read a little
in "The Linux Kernel" document and a few others, but can't say I
feel much wiser. :-) I was thinking about creating a custom "data_ready"
function that I set for the socket to be forwarded (in "struct sock"),
does this make sense? How would I go about to write the data to the
destination file/socket descriptor?

I am of course fully aware that it is not of public interest and
have certainly not intended to try getting it into the mainstream
kernel. :-) I'm just going to use it for a web server I am developing
that communicates with applications via sockets (UNIX domain for
local apps and TCP for remote), portability is not an issue in this
particular case. Another obvious use is for bouncers.

I would like to avoid the kernel -> userspace -> kernel copying
of data just to forward a packet.. The web server should be able
to scale up to a couple of thousands simultaneous connections
without significant performance penalty, so I plan to use multiple
processes or perhaps threads to avoid the bad scalability of
select()/poll().

When I (or if I :-) get more proficient in kernel hacking I will
perhaps try adding support for fully event-driven I/O handling.
Or are there perhaps any similar patches available from somewhere
already?

-- 
Joel Eriksson

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-04-18 23:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-19  1:03 Socket hack question Joel Eriksson
     [not found] ` <Pine.LNX.4.10.10104181931310.14361-100000@coffee.psychology.mcmaster.ca>
2001-04-19  2:06   ` Joel Eriksson
  -- strict thread matches above, loose matches on Subject: below --
2001-04-18 22:28 Joel Eriksson
2001-04-18 21:31 ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox