All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Eriksson <jen@ettnet.se>
To: linux-kernel@vger.kernel.org
Subject: Re: Socket hack question.
Date: Thu, 19 Apr 2001 03:03:15 +0200	[thread overview]
Message-ID: <20010419030315.A7923@seth> (raw)

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

             reply	other threads:[~2001-04-18 22:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-19  1:03 Joel Eriksson [this message]
     [not found] ` <Pine.LNX.4.10.10104181931310.14361-100000@coffee.psychology.mcmaster.ca>
2001-04-19  2:06   ` Socket hack question 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

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=20010419030315.A7923@seth \
    --to=jen@ettnet.se \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.