From: Tom Anderson on
On Sat, 20 Mar 2010, Nix wrote:

> On 19 Mar 2010, Tom Anderson said:
>
>> A possibly minor caveat is that you can't (that i can see) handle
>> several connections to a port at once, even using multiple processes.
>> You can accept one connection then exit, but you hold the listening
>> socket until you exit, so you can't have multiple processes doing that
>> in parallel. You can accept a series of connections, but not in
>> parallel.
>
> You want socat(1), which can do anything,

Okay, socat is new to me, and is very cool.

> specifically this (you want the 'fork' option to TCP-LISTEN.)

I'm still trying to figure out how i could use that and then actually deal
with the multiple connections; i can make the second stream be an EXEC of
a handler script (thus essentially using socat like a mini-inetd), or i
could create a named pipe and then work with that in the main script, or
fork that script to work with it, or i could do something similar but with
a listening unix-domain socket, which i could then connect to in the main
script or a child, or i could get socat to talk to my standard in and out,
then use bash's file descriptor operators to shuffle them off out of the
way and work with them (not sure about this one).

At this point, the choice is probably dictated by the process model i
want, so the ball is back in my court!

> Downside: enough features to drive even an Emacs user mad.

THE POWER! THE POWER!!

tom

--
Change happens with ball-flattening speed. -- Thomas Edison
From: Tom Anderson on
On Fri, 26 Mar 2010, Bruce Richardson wrote:

> Tom Anderson <twic(a)urchin.earth.li> wrote:
>
>> Oh, undoubtedly. And even easier from python. But i was specifically
>> wondering about doing it from bash - i'm really just interested in the
>> limits of what you can do in shell script. My medium-term goal here is
>> to write a noddy HTTP server in bash, for the amusement of my
>> colleagues.
>
> If you want to see the limits of shell script being tested, have a look
> at bashreduce: http://blog.last.fm/2009/04/06/mapreduce-bash-script

Nice!

tom

--
Astronomy's a fascinating subject. You look up ... and it's there. --
Patrick Moore