how to do one to many inter process communication?
hiho@ll
i have a configserver running inside my app the app itself has a forked child processes i now want that every process is configurable through a webinterface so i thought about creating one configserver which listens for a tcp connection and every forked process creates a configthread the configserver then sends data through a fifo to the configthreads and the threads answer to the server well i'm working on this for days and i have many problems with the fifo communication cause there are many threads who want to send their data to a the server back and i don't receive the stuff on configserver side (i have no idea why or how i could explain the problem in more detail) anybody has another idea how to solve such stuff? maybe another method of IPC? or some hints for working with fifo pipes would be cool thx@ll |
I've done something similar using Perl and TCP. Had probs with FIFOs. If you allow the machine to talk to itself via the loopback i'f (ie lo) you can do it this way. Also means you could later communicate from a remote machine.
|
@chrism01
yeah, its a good idea to do this so you can do remote config too i thought about this, but i don't want this to be a security hole now it doesnt matter cause it works! :D fifo's aren't the easiest way to solve this kind of stuff the problems i had with the fifo stuff: i read many simple examples and i did some examples which worked good then i tried to implement it to make something like a "fifo-configuration infrastructure" the goal was to be able to configure every process of a server seperately so i could for example change the serverport on the fly (thats cool!) the problems i had where: the configserver sends the config request to its fifo-childs and each child reads it using a configthread the thread does the configuration and sends a response back to the server! the response was my biggest problem first i didn't understand why a FIFO is a half-duplex pipe! so if you want a full duplex fifo, you have to create 2 fifos if you open the fifo O_RDWR it's only a half duplex pipe, so if the same process writes something and reads again it will read what it wrote! the second problem i had was that the configthreads write some data in the serverpipe but it wasn't created already it was because every example i read did a mkfifo and in the next line a open(); so i didn't think about using this seperately i was sending the request to the threads, did a mkfifo and opened and i only got some responses with a bit luck, because the pipe was opened too late now i do a mkfifo, send the request, open the fifo O_RDONLY and read the response ;-) the third problem was i didn't know what happens to my server fifo if many childthreads try to open the fifo using O_WRONLY and now comes a really tricky part if the server does a mkfifo then sends the request and the clients open the pipe, write the response and close it! the END OF FILE is getting sent too!! this means, if i send the request to 2 childthreads and both threads write the response and then i read from my serverfifo, the read(); returns 2 times 0 so i read first read: "RESPONSE" second read: returns 0 third read: "RESPONSE" fourth read: returns 0 so i made it part of my protocol: i send the request to the childthreads and i count how many childs got the request (if(write()>0) count++) then i checked how often read returns 0 (readcount++) if readcount==count i got every response this method seems to work very well |
All times are GMT -5. The time now is 02:27 AM. |