Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Tue, 24 Feb 2004 10:47:03 -0500 From: Rick F Nicholson To: cygwin AT cygwin DOT com Subject: Bugs: perl-libwin32-0.191-1 (Win32::Pipe->Connect) and using perl-5.8.2 open() to open an existing Win32 named pipe Message-ID: <20040224154702.GA9385@ic.delcoelect.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nFreZHaLTZJo0R7j" Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Spam-Status: No, hits=-14.8 required=4.5 tests=BAYES_00,DELCO_LOCAL_SENDER, FROM_HAS_MIXED_NUMS autolearn=ham version=2.60 X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp) on koktsv73.delcoelect.com --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I am currently writing an application that uses win32 named pipes to communicate. The random length records being sent dictated opening a file handle to the named pipe on the client and then using read() to access the record. After noticing that libwin32-0.191 had been ported to cygwin, I tried a perl named pipe server and client that I had written for debugging the app on ActiveState Perl-5.8.2. I noticed the following: Win32::Pipe-Connect() is either non-blocking, doesn't get passed the timeout value when the pipe is created or has a very low timeout value. This could also be an interpretation problem. The behavior I had expected was that when no client is connected, the Win32::Pipe-Connect() would wait for a client to connect until a timeout occurs. The behavior I got was that Win32::Pipe-> Connect() returns immediately with "True" if a client is connected and "False" if one has not. Perl open() on the client side doesn't seem to understand using UNC to open an existing named pipe. For example if I do the following: open(PIPE, "<", "\\\\.\\pipe\\my named pipe"); I get an error message: "Mount device busy." After trying to use open() to connect to the named pipe, No other connections are possible. It would appear that open is interpreting "\\\\.\\pipe\\my named pipe" as a mount request. A perl script illustrating the problem is attached. Vital statistics are: Cygwin DLL version info: DLL version: 1.5.7 DLL epoch: 19 DLL bad signal mask: 19005 DLL old termios: 5 DLL malloc env: 28 API major: 0 API minor: 109 Shared data: 3 DLL identifier: cygwin1 Mount registry: 2 Cygnus registry name: Cygnus Solutions Cygwin registry name: Cygwin Program options name: Program Options Cygwin mount registry name: mounts v2 Cygdrive flags: cygdrive flags Cygdrive prefix: cygdrive prefix Cygdrive default prefix: Build date: Fri Jan 30 19:32:04 EST 2004 CVS tag: cr-0x9e Shared id: cygwin1S3 and perl 5.8.2-1 perl-libwin32 0.191-1 Thanks in advance --nFreZHaLTZJo0R7j Content-Type: application/x-perl Content-Disposition: attachment; filename="pipe_as_read_fh.pl" Content-Transfer-Encoding: quoted-printable #!/usr/bin/perl=0D =0D use Win32::Pipe;=0D use Sys::Hostname;=0D my $PipeName =3D "My Named Pipe";=0D =0D $| =3D 1; # Set output buffering to AUTO_FLUSH=0D =0D print "Spawning server and client\n" ;=0D =0D SPAWN: {=0D my $pid;=0D print "Preparing to fork\n" ;=0D =0D if($pid=3Dfork()) {=0D print "Spawning server\n" if defined ($DEBUG);=0D =0D np_server() ;=0D =0D } elsif (defined($pid)) {=0D print "Spawning client\n" if defined ($DEBUG);=0D =0D np_client() ;=0D =0D } elsif ($! =3D~ /No more process/) {=0D sleep 5;=0D print "Respawning\n" ;=0D redo SPAWN;=0D } else {=0D die "Can't fork: $!\n";=0D }=0D }=0D =0D sub np_server {=0D =0D my $Pipe_Error ;=0D my $Client_Disconnected;=0D my $Pipe_Connect_Status;=0D my $Test_Done ; =0D my $In;=0D =0D print "NP Server: Creating pipe \"$PipeName\".\n";=0D =0D =0D if( ($Pipe =3D new Win32::Pipe( $PipeName, NMPWAIT_WAIT_FOREVER, PIPE_T= YPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT)) )=0D {=0D print "NP Server: Done creating pipe.\n";=0D =0D $User =3D getlogin() ;=0D print "NP Server: Pipe opened by $User.\n";=0D $Pipe_Error =3D 0;=0D $Test_Done =3D 0;=0D while(!$Pipe_Error && !$Test_Done) {=0D $Client_Disconnected =3D 0;=0D print "NP Server: Waiting for client to connect\n";=0D =0D while(( $Pipe->Connect()) && !$Pipe_Error && !$Client_Disconnected && = !$Test_Done) {=0D print "NP Server: Client connected\n";=0D my $Data =3D "Pipe writen by $User. Time on " . hostname() . " is: " . lo= caltime() . "\n";=0D =0D if (!$Pipe->Write( $Data )) {=0D print "NP Server: Error writing pipe\n";=0D $Pipe_Error =3D 1;=0D next ;=0D }=0D if (!($In=3D$Pipe->Read())) {=0D print "NP Server: Error reading pipe\n";=0D $Pipe_Error =3D 1;=0D next ;=0D }=0D $Client_Disconnected =3D 1 if ($In eq "DONE") ;=0D $Test_Done =3D 1 if ($In eq "FINIS") ;=0D print "NP Server: Test Done\n" if ($In eq "FINIS") ;=0D =0D print "NP Server: Disconnecting...\n";=0D $Pipe->Disconnect();=0D $Pipe->Close() if ($Test_Done);=0D =0D }=0D =0D print "NP Server: Client Disconnected\n" if ($Client_Disconnected);; = print "NP Server: Pipe Error -- $|\n" if ($Pipe_Error);=0D print "NP Server: Test Done\n" if ($Test_Done);=0D sleep 1;=0D }=0D }=0D else=0D {=0D print "\nNP Server: Could not create pipe Error: " . Win32::Pipe::Error . = "\n";=0D }=0D }=0D =0D sub np_client {=0D =0D my $FQNPipeName =3D "\\\\.\\pipe\\" . $PipeName;=0D print "NP Client: Connecting to $FQNPipeName via Win32::Pipe\n";=0D =0D if( $Pipe =3D new Win32::Pipe( $FQNPipeName ) )=0D {=0D print "NP Client: Pipe has been opened, read data from it...\n";=0D my $In =3D $Pipe->Read();=0D print "NP Client: Server sent the client -- $In\n";=0D print "NP Client: Closing the pipe\n";=0D $Pipe->Write("DONE");=0D $Pipe->Close();=0D }=0D else=0D {=0D print "NP Client: Error connecting: " . $Win32::Pipe::Error . "\n";=0D }=0D print "NP Client: Connecting to $FQNPipeName via open()\n";=0D =0D sleep 1;=0D if( open(PIPE, "+<", $FQNPipeName ) )=0D {=0D my $In;=0D print "NP Client: Pipe has been opened, reading data from it...\n";=0D =0D read PIPE, $In, 70 ;=0D print "NP Client: Server sent the client -- $In\n";=0D print PIPE "DONE", 4;=0D =0D close(PIPE);=0D }=0D else=0D {=0D print "NP Client: Error connecting via open(): $!\n";=0D }=0D print "NP Client: Finishing the test\n";=0D =0D if( $Pipe =3D new Win32::Pipe( $FQNPipeName ) )=0D {=0D print "NP Client: Finishing the test\n";=0D =0D $Pipe->Write("FINIS");=0D $Pipe->Close();=0D }=0D else=0D {=0D print "NP Client: Error connecting: " . $Win32::Pipe::Error . "\n";=0D }=0D print "NP Client: Test Done\n";=0D =0D }=0D --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --nFreZHaLTZJo0R7j--