[ksh93-integration-discuss] Re: [perf-discuss] Can |recv()| be used on a pipe in Solaris ?

Glenn Fowler gsf at research.att.com
Wed Sep 6 01:04:40 PDT 2006


On Wed, 06 Sep 2006 09:02:31 +0200 Casper.Dik at Sun.COM wrote:
> >but that doesn't answer the question "does recv() work on pipes in solaris?"
> >there are some systems with pipe!=socket with similar documentation
> >for which recv() works on pipes

> It's not a socket so it is not supposed to work and does not work.

> On some systems, pipes are created with socketpair() and they are
> a form of sockets.

I guess I'm dating myself here -- some shall's snuck into the recv() docs
and checking deeper, my most recent complaint about a recv() implementation
(not solaris) is that, instead of failing ENOTSOCK for a pipe, acted like
read() by ignoring MSG_PEEK

> >a general note: this is a big hole in the official and de-facto standards
> >there is no consistent (across implementations) way to peek on a pipe, and
> >thus no efficient way to read exactly one line from a pipe -- what is
> >needed is a call that peeks on any fd open for reading

> That's probably because few people need it.

there's conscious need and subconscious need

here is a response from dgk on the ast-users list to a user who
"optimized" a script by trading a long pipeline for one pipe
into while read; do -- and ended up running ~7 times slower

> The
> 	... | while read ;do...;done
> is a problem for the shell.  The problem is that if there are any
> commands between do and done, then the shell doesn't know whether
> any of these use standard input and therefore cannot do read-aheads.
> Therefore, the read comamnd cannot read past the new-line. 
>
> On systems that allow recv() on a pipe, it can peek ahead
			^^^^
                 (or ioctl(I_PEEK))
> to find the new-line and read() can read() a line at a time.
> Otherwise, it needs to read a byte at a time. 
...
> This can make a big difference.

so in this case "need" translates to: how often is the pipe to while
read paradigm used




More information about the ksh93-integration-discuss mailing list