gmpassos has asked for the wisdom of the Perl Monks concerning the following question:

Perl 5.8 use for default the DISCIPLINE :crlf on sockets too! How can +I disable this?!!!! I tried two things to fix, but nothing: use open (IN => ":raw", OUT => ":raw") ; and: binmode($sock, ":raw"); Anyone know how to disable the crlf of Perl 5.8? CRLF make any "\n" to + be converted to "\012\015" ("\r\n"). But I'm using the socket to sen +d binary data, and they come with erro if the CRLF are on!!!!

Edit by tye

Replies are listed 'Best First'.
Re: Perl 5.8 no :crlf on Socket!!!!!!
by Abigail-II (Bishop) on Jul 23, 2002 at 11:39 UTC
    If this is indeed the case, I urge you to use perlbug and send a bug report. This sounds like a serious problem.

    The manual page about PerlIO states how to override the default:

           The default can be overridden by setting the environment
           variable PERLIO to a space separated list of layers (unix
           or platform low level layer is always pushed first).
    

    Abigail

      This was tested with Perl 5.8-RC2, I got now the 5.8 
      release and will compile it for test! If you want to test 
      is very simple, just make a socket srv and client and send 
      something like "A\nA" from the client and see what it 
      reads, 65,10,65 or 65,13,10,65. Remember this bug is for 
      Win32.
      
      I tested with
      $ENV{PERLIO} = ":raw" ; 
      and nothing (still RC2).
      
      To get speed, here are my test script:
      
      SERVER:
      
      #!/usr/bin/perl $|=1; $ENV{PERLIO} = ":raw" ; sub SOCKET_init { $| = 1 ; use Socket;my $p=getprotobyname('tcp'); socket(SRV,PF_INET,SOCK_STREAM,$p); setsockopt(SRV,SOL_SOCKET,SO_REUSEADDR,pack('l',1)); my($opn,$try); while($opn!=1 && $try<=20){ if(bind(SRV,sockaddr_in($_[0],INADDR_ANY))){$opn=1} else{$try++;sleep(1)}} if($opn!=1){print"ERROR! Port $_[0] in use.\n";exit} listen(SRV,SOMAXCONN);my($wpid,$pad)=(0); $SIG{CHLD}=\&REAPER;my $CLT; for($wpid=0;&ACT_CLT;$wpid=0,close(NS)) { next if $wpid and not $pad;my($p,$a)=sockaddr_in($pad); my @i=unpack('C4',$a);$CLT++;$PORTS{$CLT}=$p; $IPS{$CLT}=join('.',@i);my $sl=select(NS);$|=1; select($sl);if($_[1]=~/^(1|ye?s?|si?m?)$/i){ &SPAWN($CLT)}else{&Server_DO($CLT)}} sub REAPER{$wpid=wait;$SIG{CHLD}=\&REAPER} sub ACT_CLT{return($pad=accept(NS,SRV)) || $wpid} sub SPAWN { my ( $CLIENT_id ) = @_ ; my $pid ; if (!defined($pid = fork)) { print "cannot fork: $!\n" ; return ;} elsif ($pid) { return ;} exit &Server_DO($CLIENT_id) ; } } sub Server_DO { # Your commands to do whe the client are connected: my ( $CLIENT_id ) = @_ ; print "New Client! <$CLIENT_id>\n" ; print "PORT: $PORTS{$CLIENT_id}\n" ; print "IP: $IPS{$CLIENT_id}\n" ; while( sysread(NS, $buffer , 3) ) { &BYTES($buffer) ; $var = "A\nA" ; print NS $var ; exit; } print "Client $CLIENT_id DOWN!\n" ; close(NS) ; } my $port = 2345 ; my $SRV_fork = 0 ; print "Sock Init\n" ; &SOCKET_init($port,$SRV_fork) ; # Start the server. exit; ######### # BYTES # ######### sub BYTES { my @d = split(//s , @_[0] ); foreach my $d_i ( @d ) { my $s = unpack("C", $d_i ) ; print "$s\n" ; } }
      CLIENT:
      
      #!/usr/bin/perl use IO::Socket ; $ENV{PERLIO} = ":raw" ; $|=1; my $port = 2345 ; my $host = 'localhost' ; my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => 30 , ) ; if (! $sock) { die "ERROR! Ca'nt connect\n" ;} $sock->autoflush(1); print $sock "A\nA" ; sysread($sock, $read , 3) ; &BYTES($read) ; close($sock) ; exit; sub BYTES { my @d = split(//s , @_[0] ); foreach my $d_i ( @d ) { my $s = unpack("C", $d_i ) ; print "$s\n" ; } }
Re: Perl 5.8 no :crlf on Socket!!!!!!
by demerphq (Chancellor) on Jul 24, 2002 at 09:42 UTC
    Please do not use PRE tags for your text. It makes it fixed format and hard to read. Use CODE tags or standard HTML markup.

    Thanks

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Re: Perl 5.8 no :crlf on Socket!!!!!!
by Courage (Parson) on Jul 24, 2002 at 06:16 UTC
    I confirm that behaviour of your code is changed in 5.8.0 compared to 5.6.1. Sad.

    Anyway, when I set PERLIO environment variable to ":raw" from command shell where perl runs, I got desired "65\n10\n65" result. Please notice that $ENV{PERLIO}=":raw"; in your program does not helps, probably because it's too late.

    OTOH I'll try looking at your code in more detail later.

    Courage, the Cowardly Dog.

      Now I put the $ENV{PERLIO} inside BEGIN and still doesn't 
      work with Perl 5.8-RC2.
      
      sub BEGIN { $ENV{PERLIO} = ":raw" ; }
      
      Tomorrow I will get the final release of 5.8 and compile, 
      bacause now is 3AM here!
      
      If someone already have the final release of Perl 5.8 
      compiled on Win32, please check this, if it still have the bug send your reply.
      
      "The creativity is the expression of the liberty".
      
        sub BEGIN{...} still not enough. Try changing your environment variable from control panel, or special bat file that starts your script, or whatever way you find appropriate.

        I tried 5.8.0 release, and also tried BEGIN{} block.

        BTW I asked p5p list for knowledge, and hope they will shed a light on this.

        Courage, the Cowardly Dog