Hi all.

I have a dear question to ask. This topic involves sockets, pipes, fork and daemon processes. I will start by trying to explain the sceneario to the best that I can. I have a server and a "worker".

Server: daemon process responsible for handling new socket connections and message passing between the worker and from other clients.

Worker: daemon process responsible for accessing external networks using sockets and
communicating information from those networks to the server.

So here is the scenario. The server accepts conections. If a new client connects, then I create a pipe to the worker.

open ($MYPIPE[$IDX], "| worker");

this works fine.

Now in the worker process, it connects to a remote network, logs on and waits for events.
I have set up the worker to only accept reading from STDIN based on the first event received from the external network. I do this by forking a process and while(1) read from standard IN.

$pid = fork();
if ($pid == 0) {
while(1) {
#read block
$input = <STDIN>;
#then i repley and create a message to be # sent to the server
$IpcMsg = &reply( $conn, $from, input);
#call create and connect to server
$MSWSD = &CreateAndConnectSD;
# write to socket the message
print $MSWSD "$IpcMsgn"
# flush the pipe
&flushSD ( $MSWSD );
&closeSD ( $MSWSD );
$input = '';
} #endwhile

again this works fine if i was using this process as a standalone, IE without the server.

So now that i have created a pipe to "worker" i want to write some contents to the pipe so it can relate the message to the external network. In the server, I have:

select( $MYPIPE[$IDX] );
# you go into write block if you don't have n , STDIN doesn't flush in worker
print "$msg[$MSGCONTENT]n" &#0124; &#0124; warn("nUserMSG: couldn't write to work:$msg[$MSGCONTENT]nSysError $!");
select (STDOUT); #restore STDOUT

now my problem is when i do this, the worker will respond correctly in everything above except that the thread will go into an infinite loop ignoring the read from STDIN the second, third etc time. and plus it sends the same message the was first in the STDIN buffer.

I anybody has any suggestions, comments or anything else i'm ready for discussion

Thanks in advance