hi,
    I have write a script to expose a COM port as tcp server.in the readComm 
subroutine ,the thread just block in the line:
    my $ret = syswrite($sock,$buf);
can anybody tell me why syswrite blocked here ? thansk.

following is my code:
=========================================================
use threads;

while(1){
 my $sock = $serverSock->accept();
 $sock->autoflush(1);
 print "client connected.\n";

 # thread transfer data from com to socket
 my $thr1 = threads->new(\&readComm,$sock,$commPort);
 # thread transfer data from socket to com
 my $thr2 = threads->new(\&writeComm,$sock,$commPort);
 $thr2->join();
 $thr1->join();
 print "client disconnect.\n";

}
#
# read from comm and write to socket fd
#
sub readComm {
 my $sock = shift;
 my $commPort = shift ;
 while(1){
  my ($cc,$buf) = $commPort->read(512);
  print "read comm loop\n";
  if($cc > 0){
   print "begin write to socket.\n";
   my $ret = syswrite($sock,$buf);
   $ret or last;
   print "write $ret byte[s] to socket.\n";
  }
 }
  print "thread ";
  print threads->self()->tid();
  print " exit : [$^E]\n";
}

#
# read from socket fd and write to comm
#
sub writeComm {
 my $sock = shift;
 my $commPort = shift;
 my $buf='';
 while(1){
     my $ret= sysread($sock,$buf,1024);
     print "write comm loop\n";
     $ret or last;
     if($ret > 0){
      print "begin write to comm.\n";
      $commPort->write($buf);
      print "write $ret byte[s] to comm.\n";
     }
 }
  print "thread ";
  print threads->self()->tid();
  print " exit : [$^E]\n";
}

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to