[boulder.pm] unblocked pipes
Amar Vattakandy
amar.vattakandy at ia.nsc.com
Thu Aug 3 15:44:20 CDT 2000
Finally, found the solution. Thanx to you guys.. And the answer is in
setting the
non bocking flag on fctl. Here is a snippet of code, if any one fall into
the same pit
that I was in for the last couple of days.
==
use Tk ;
use Socket ;
use Fcntl ;
use Tk::FileSelect ;
use IO::Handle;
require Tk::Dialog;
# Open the pipes for communication between the background process
# and the GUI
socketpair(BKGROUND,GUI,AF_UNIX,SOCK_STREAM,PF_UNSPEC) or die "Bad
Socketpair $!";
$SockFlags = '';
fcntl(BKGROUND,F_GETFL,$SockFlags) or die "Cant get Flags: $!";
$SockFlags |= O_NONBLOCK;
fcntl(BKGROUND,F_SETFL,$SockFlags) or die "Cant set Flags: $!";
fcntl(GUI,F_GETFL,$SockFlags) or die "Cant get Flags: $!";
$SockFlags |= O_NONBLOCK;
fcntl(GUI,F_SETFL,$SockFlags) or die "Cant set Flags: $!";
BKGROUND ->autoflush(1);
GUI ->autoflush(1);
==
Now, the forked processes could talk to each other like
$blahFromGUI = <GUI> ;
or
printf (GUI "$blahToGUI \n");
etc...
Call me stupid, but I had lost a lot of time debugging apps with no \n in
their
messages and expected the autoflush to work..
Anyway, the rest of the code from the background process
while (1)
{
$blahFromGUI = <GUI>;
if (defined $blahFromGUI)
{
chomp($blahFromGUI);
printf("Child: Got $blahFromGUI\n");
}
else
{
printf("Child Did Not Receive Anything \n");
}
sleep 1 ;
}
Hoping someone would find it useful..
Amar Vattakandy wrote:
> Any help on this would be appreciated:
>
> | I have a parent and a child (thru forking) that needs to talk to each
> | other thru a
> | socket pair pipe. Communication works fine, but the problem happens
> when
> | I try
> | to read from a pipe that has no data in it. The read, which is like
> | $readline = <CHILD> ;
> | keeps waiting till the child has some data in it. I know that this is
>
> | how it is supposed
> | to work, but is there any way I could check whether there is some
> data
> | in the pipe
> | before I read the pipe ?
> |
> | Thanx
> | Amar
>
> --
>
> *********************************
> Amar Salaj V
> National Semiconductor Corporation
> 1351 S Sunset St.
> Longmont CO-80501
>
> Ph : 303 774 5181
> Fax : 303 774 5801
>
> *********************************
--
*********************************
Amar Salaj V
National Semiconductor Corporation
1351 S Sunset St.
Longmont CO-80501
Ph : 303 774 5181
Fax : 303 774 5801
*********************************
More information about the Boulder-pm
mailing list