Re: PROPOSAL: extend pipe() to support NULL argument.

From: Amerigo Wang
Date: Fri Jul 03 2009 - 03:13:16 EST


On Fri, Jul 03, 2009 at 01:42:12PM +0800, Changli Gao wrote:
>On Fri, Jul 3, 2009 at 1:19 PM, Amerigo Wang<xiyou.wangcong@xxxxxxxxx> wrote:
>>
>>
>> Yes, exactly.
>> Inventing a new API is better than modifying pipe(2), IMO.
>>
>> BUT I still don't agree that you really need this... I think you
>> can add a flag or something like that to an fd to do this, e.g.
>>
>> Â fcntl(fd, F_SETFD, FD_PIPERW);
>>
>> Isn't this better?
>You don't understand my need. I don't want to change a RDONLY or
>WRONLY pipe to a RW one, but I want to pipe() return just one RW pipe
>instead.

This is exacly what I meant by that example.

>It seems you prefer pipe0() to pipe(NULL).

pipefd() seems better.

>>>You don't know my meaning. As a proxy server, there maybe lots of
>>>connections to maintain, and these connections will keep open for a
>>>long time. If the data received can be sent in a relay cycle, the
>>>kernel buffer can be reused. If not, the kernel buffer must be
>>>reserved. When there are lots of these kinds of connections, lots of
>>>kernel buffers must be reserved. At this time, whether two fds per
>>>kernel buffer or one fds per kernel buffer matters.
>>
>> SHow us the code, please.
>>
>If you don't know my need after reading my words, I don't think you
>can understand the fake code.

No, code is *much* better than any of your words.

>The fake code:
>
>main thread:
>
>while (1) {
> fd = accept();
> pthread_create(worker, fd);
>}
>
>worker thread(assume data is transfered just from client to server for
>simplification):
>
>serv_fd = connect();
>while (1) {
> select(fd, RD);
> pipe = get_pipe_from_poll();
> n = splice(fd, pipe);
> while (n > 0) {
> n -= splice(pipe, serv_fd);
> }
> put_pipe_to_poll();
>}
>close(serv_fd);
>close(fd);

If saving one fd really helps here, probably you want to
save more, you will need a syscall like:

int splice_without_new_fd(int infd, int outfd);

But splice(2) is designed to be as it is. You need to increase
your fd limit, instead of saving one by pipe().
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/