[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Pipes
Hello!
> I have a few questions about pipes and such. I am writing two programs
> that need to communicate with each other in that way:
>
> prg1 creates a pipe, starts prg2 and waits, until prg2 writes
> something into that pipe, then prg2 waits until prg1 writes something
> and so on.
>
> My approach was this:
> prg1 uses fpipe and passes the file handles to prg2 (cia command
> line). But obviously the file handles are not systemwide, so when prg2
> tries to use the passed filehandles, it gets an EIHNDL from Fwrite.
Sure, that's right. File handles are process private. That's also not the
way to use anonymous pipe. The right way is: create the pipe with fpipe,
fork itself, the child process can now replace itself with another program
that inherit open file handles from it's parent (only execption is if the
close-on-exec flag is set; see Fcntl(F_GETFD/F_SETFD)). Every shell for
example use this way to realize output/input redirection.
> However, when prg2 tries to write to that pipe, it gets and EACCDN
> error code.
> Why is that? Is the pipe I created earlier on only unidirectional? If
> yes, how do I get a bidirectional pipe?
Pipes are per definition unidirectional. Beside from that I strongly
suggest not to use the u:/pipe solution. This is a weird interface from
old MiNT days. Just use Fpipe() in the right way.
> Or are there any other solutions for the type of communication I want?
Sure, you can use local domain sockets (also names unix domain sockets)
for bidirectional communication. They are builtin starting from 1.16,
under 1.15 they are part of MiNTNet (sockdev.xdd).
You can lookup any unix documentation about socket(PF_LOCAL, ...) and
friends. The FreeMiNT/MiNTNet sockets are almost 100% compatible. Btw.
under 1.16 the Fpipe() is just a wrapper about a local domain socket.
Other ways of interprocess communication are Pmsg() and shared memory.
Tschuess
...Frank
--
ATARI FALCON 040 // MILAN 060
-----------------------------------------
http://www.cs.uni-magdeburg.de/~fnaumann/
e-Mail: fnaumann@freemint.de