lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


steve donovan wrote:
>
> popen2 traditionally returns _two_ file objects, one for writing and
> one for reading.

As I said, it doesn't matter.  At the moment you block in
a read or write you are unable to process data in the
other direction and the application may deadlock.

> How about this implementation?
> 
> http://mysite.mweb.co.za/residents/sdonovan/popen.zip

It is prone to deadlocks.

And btw, the unix version leaks fds in erros paths and
passes to many fds to the spawned process. 

> (on Fedora Core 5)
> > require 'popen'
> > w,r = popen.popen2('cat')
> > w:write(string.rep('*',64*1024))
> > w:close()
> > res = r:read('*a')
> > = #res
> 65536
> 
> Have I missed something here?

Just try something bigger.

It's hard to detect the buffer sizes. Possibly
Linux handles exactly 64k at the moment (8 pages
for each pipe = 8*4k*2 = 64k).  If it were using
sockets the limits may be even bigger, something
like 64k or 128k per direction.  Traditional unix
had 4k.

And, with a strange "cat", one that reads all
data until EOF and only then writes everything
out, you will never experience a deadlock.
Only out of memory conditions ;-)

Ciao, ET.