multithreading - C - Sending a PIPE FD, that was created in a thread, to the parent process through a FIFO -
i'm trying create small server chat app, using internet domain sockets. server composed of dispatcher , main-server.
the dispatcher in charge of detecting new connection requests , handling them in new thread. thread sends information main-server through fifo. bundle sent thread has pipe fd created, main-server can communicate response. dispatcher initialised main-server fork , using execve().
the problem can't write data pipe server. [ebadf bad file descriptor] error.
i understand i'm supposed pass pipe fd parent process child process, solution doesn't work me because don't know how many pipes i'm going need @ same time. moreover, don't want create fifo each thread, means need create new file every thread active , think not elegant solution.
so summarize:
- is possible use pipes in manner?
- if problem use of pipes, why can't pass pipe fd through fifo , use in process? read possible communicate between unrelated processes pipes using unix domain sockets pass fd. difference between these approaches?
- what solution recommend?
if create dispatcher main server fork
won't share file descriptor table: dispatcher copy of file descriptors, files or sockets dispatcher opens afterwards open in dispatcher.
to create dispatcher should use method shares file descriptor table. example can use pthreads
thread. if use linux can replace fork
low level clone
function, including clone_files
in flags.
Comments
Post a Comment