[27546] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9099 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 28 18:06:00 2006

Date: Tue, 28 Mar 2006 15:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 28 Mar 2006     Volume: 10 Number: 9099

Today's topics:
        Binary opcodes comatible? <bol@adv.magwien.gv.at>
        Buffered socket I/O with sysread-style blocking? <jsm@jmarshall.com>
    Re: Buffered socket I/O with sysread-style blocking? xhoster@gmail.com
    Re: Buffered socket I/O with sysread-style blocking? <jsm@jmarshall.com>
    Re: Buffered socket I/O with sysread-style blocking? <1usa@llenroc.ude.invalid>
        characters to ascii <vanluynm@NOSPAM.iinet.net.au>
    Re: characters to ascii <noreply@gunnar.cc>
    Re: characters to ascii <tadmc@augustmail.com>
    Re: Concise idiom sought <rvtol+news@isolution.nl>
    Re: Strange problem with IO::Socket::connected() <ThomasKratz@REMOVEwebCAPS.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 28 Mar 2006 14:06:54 +0200
From: "Ferry Bolhar" <bol@adv.magwien.gv.at>
Subject: Binary opcodes comatible?
Message-Id: <1143547617.252198@proxy.dienste.wien.at>

Hi,

under Perl 5.6, I use the B::ByteCode.pm module to convert some programs
into binary
format and re-run them later using ByteLoader.pm.

Can I run programs converted in this way with other Perl version as well?
For example,
can I run a 5.6 converted program under 5.8 or 5.9 as well? And even on
5.005?

MTIA, and kind greetings,

Ferry

-- 
Ing. Ferry Bolhar
Municipality of Vienna, Department 14
A-1010 Vienna / AUSTRIA
E-mail: bol@adv.magwien.gv.at




------------------------------

Date: Tue, 28 Mar 2006 11:33:04 -0800
From: James Marshall <jsm@jmarshall.com>
Subject: Buffered socket I/O with sysread-style blocking?
Message-Id: <20060328110019.X81969@jmarshall.com>

I need to read data from a socket, with sysread-style blocking (i.e. block 
if no data available, but return immediately with anything that is 
available, possibly less than the requested amount).  Is this possible 
when using buffered I/O (read(), <S>), or only with non-buffered I/O 
(sysread(), recv())?

I can't use non-blocking I/O, because that implies a busy loop when no 
data is available (doesn't it?).

I can't use select(), because that won't work with buffered I/O (will 
it?).

I can't really use signals, because the program can't really continue 
until it has the data.


How does one do this?  Am I missing something, or making a bad assumption 
somewhere?  Has anyone documented the "heavy wizardry" that's required to 
use buffered I/O and non-buffered I/O on the same socket?  I'd really 
rather not rewrite my (large) program to use unbuffered I/O... that could 
get messy.  Socket flags and fcntl() etc. are allowed, as long as it's 
reasonably portable.  Standard modules are OK too, but ideally for this 
application I don't want to require the user to install extra modules. 
Since that's not restrictive enough, ideally I'd also like it to run in 
Perl 5.6.1, but I'm flexible on that.

Thanks a lot for any ideas!

James
 ............................................................................
   James Marshall      james@jmarshall.com       Berkeley, CA      @}-'-,--
                         "Teach people what you know."
 ............................................................................


------------------------------

Date: 28 Mar 2006 20:50:32 GMT
From: xhoster@gmail.com
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <20060328155935.074$Y5@newsreader.com>

james@jmarshall.com wrote:
> I need to read data from a socket, with sysread-style blocking (i.e.
> block if no data available, but return immediately with anything that is
> available, possibly less than the requested amount).  Is this possible
> when using buffered I/O (read(), <S>), or only with non-buffered I/O
> (sysread(), recv())?

I don't think that it is possible with buffered I/O.  Why have buffered I/O
if you don't want it to actually do buffering?  I guess you could specify a
length of 1 for each read.  I don't see what that would get you, but then
again I don't see what you trying to accomplish in the first place.

>
> I can't use non-blocking I/O, because that implies a busy loop when no
> data is available (doesn't it?).

I'm sure exactly what you mean by non-blocking I/O.  I seems that when
people say in a perl context, they mean that they are using select or
IO::Select, but since you meantion select separately, maybe you don't mean
that.

>
> I can't use select(), because that won't work with buffered I/O (will
> it?).

It will under some conditions and/or interpretations.  The trick is that
you need to empty the buffer before the next call to select.  This results
in semi-nonblocking, where you won't block waiting for the client to start
sending a message, but then once it is started you block until the whole
message is received.  Often, this type of thing is good enough.  But it
seems like you want the opposite, blocking until a message is started, but
then nonblocking until it is all received.  I guess I just don't see the
point in that.

>
> I can't really use signals, because the program can't really continue
> until it has the data.

Then why worry about not blocking?

>
> How does one do this?  Am I missing something, or making a bad assumption
> somewhere?  Has anyone documented the "heavy wizardry" that's required to
> use buffered I/O and non-buffered I/O on the same socket?  I'd really
> rather not rewrite my (large) program to use unbuffered I/O... that could
> get messy.

Why?  If all you use is read, you just need to change each one of them to
sysread.  Not a day at the beach, but still not too bad.  If you use things
other than read on these handles, what are they?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: Tue, 28 Mar 2006 14:04:43 -0800
From: James Marshall <jsm@jmarshall.com>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <20060328131057.B12520@jmarshall.com>

Thanks for the response.  Comments interspersed below:


On Tue, 28 Mar 2006 xhoster@gmail.com wrote:

> james@jmarshall.com wrote:
>> I need to read data from a socket, with sysread-style blocking (i.e.
>> block if no data available, but return immediately with anything that is
>> available, possibly less than the requested amount).  Is this possible
>> when using buffered I/O (read(), <S>), or only with non-buffered I/O
>> (sysread(), recv())?
>
> I don't think that it is possible with buffered I/O.  Why have buffered 
> I/O if you don't want it to actually do buffering?  I guess you could 
> specify a length of 1 for each read.  I don't see what that would get 
> you, but then again I don't see what you trying to accomplish in the 
> first place.

I use the <> input operator (which is buffered) in several different ways. 
Also, it's nice to not handle interrupted system calls, which (at least 
according to Camel) one must do when using sysread() and presumably 
recv().

Reading one character at a time would be too inefficient for this app.


>> I can't use non-blocking I/O, because that implies a busy loop when no
>> data is available (doesn't it?).
>
> I'm sure exactly what you mean by non-blocking I/O.  I seems that when 
> people say in a perl context, they mean that they are using select or 
> IO::Select, but since you meantion select separately, maybe you don't 
> mean that.

By "non-blocking", I mean when the socket has the O_NONBLOCK flag set.


>> I can't use select(), because that won't work with buffered I/O (will
>> it?).
>
> It will under some conditions and/or interpretations.  The trick is that 
> you need to empty the buffer before the next call to select.  This 
> results in semi-nonblocking, where you won't block waiting for the 
> client to start sending a message, but then once it is started you block 
> until the whole message is received.  Often, this type of thing is good 
> enough.  But it seems like you want the opposite, blocking until a 
> message is started, but then nonblocking until it is all received.  I 
> guess I just don't see the point in that.

OK, interesting.  Thanks for the info.

What I want to do is read and process the (in this case HTML) data as it 
comes in, rather than wait for the whole resource to download, or even 
wait for a whole buffer block.  But if there's no incoming data waiting, I 
don't want the program to eat up the CPU in a busy loop-- the program is a 
CGI script that may have many instances running simultaneously, and busy 
loops are bad style anyway.


>> I can't really use signals, because the program can't really continue
>> until it has the data.
>
> Then why worry about not blocking?

Because I *can* process some data from a partial read.


>> How does one do this?  Am I missing something, or making a bad assumption
>> somewhere?  Has anyone documented the "heavy wizardry" that's required to
>> use buffered I/O and non-buffered I/O on the same socket?  I'd really
>> rather not rewrite my (large) program to use unbuffered I/O... that could
>> get messy.
>
> Why?  If all you use is read, you just need to change each one of them 
> to sysread.  Not a day at the beach, but still not too bad.  If you use 
> things other than read on these handles, what are they?

That's probably what I'll end up doing, but I don't think the switch is so 
simple (is it?).  I also might try to read one HTML tag at a time using <> 
with $/=='>', though that has pitfalls and is somewhat inefficient.

Besides read(), I use <>.  It's handy for line-oriented input.  HTTP is an 
odd case in that an HTTP message starts with textual line-oriented data, 
and then changes to potentially binary data.  Those can even be mixed 
together, in the case of chunked data.


Thanks,
James
 ............................................................................
   James Marshall      james@jmarshall.com       Berkeley, CA      @}-'-,--
                         "Teach people what you know."
 ............................................................................


------------------------------

Date: Tue, 28 Mar 2006 22:48:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Buffered socket I/O with sysread-style blocking?
Message-Id: <Xns9794B5460B629asu1cornelledu@127.0.0.1>

James Marshall <jsm@jmarshall.com> wrote in
news:20060328131057.B12520@jmarshall.com: 

> What I want to do is read and process the (in this case HTML) data as
> it comes in, rather than wait for the whole resource to download, or
> even wait for a whole buffer block.  But if there's no incoming data
> waiting, I don't want the program to eat up the CPU in a busy loop--
> the program is a CGI script that may have many instances running
> simultaneously, and busy loops are bad style anyway.

You are making a huge assumption that is most likely not warranted.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Tue, 28 Mar 2006 19:24:13 -0800
From: "Murray R. Van Luyn" <vanluynm@NOSPAM.iinet.net.au>
Subject: characters to ascii
Message-Id: <44291a8d$0$21298$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

Hi,

I want to find out the ascii value of a single character in a variable, and 
then print some characters using their ascii values.

How is this done in Perl?

Regards,
Murray R. Van Luyn. 




------------------------------

Date: Tue, 28 Mar 2006 13:21:24 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: characters to ascii
Message-Id: <48skhkFlsddvU1@individual.net>

Murray R. Van Luyn wrote:
> I want to find out the ascii value of a single character in a variable, and 
> then print some characters using their ascii values.

     perldoc -f ord
     perldoc -f chr

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Tue, 28 Mar 2006 07:27:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: characters to ascii
Message-Id: <slrne2iedp.uqt.tadmc@magna.augustmail.com>

Murray R. Van Luyn <vanluynm@NOSPAM.iinet.net.au> wrote:

> I want to find out the ascii value of a single character in a variable, 


   perldoc -f ord


> and 
> then print some characters using their ascii values.


   perldoc -f print
   perldoc -f chr


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 28 Mar 2006 15:57:37 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Concise idiom sought
Message-Id: <e0bmhm.19s.1@news.isolution.nl>

Anno Siegel schreef:
> Dr.Ruud:
>> Anno Siegel:
>>> Dr.Ruud:
>>>> Randal L. Schwartz:

>>>>>         defined $_ or $_ = 1 for $base_ref->{pl};
>>>>
>>>> Alternatively:
>>>
>>> Where has $v come from?
>>
>> It is just a replacement for the $base_ref->{pl}
>> Does $v suffer much less from the <expensive "find the lvalue"> blues
>> than $v, making it an invalid stand-in?
>
> Well, it's a simple variable, I don't see a reason to alias it to
> another simple variable.

I agree, I lost meaning in my simplification.


> With arrays and hashes, access to an
> element is a two-step process, so "... for $base_ref->{pl}" saves a
> step for each time $_ is used on the left side.
>
> Too bad it doesn't work with exists() and delete(), but that would
> take more than an lvalue.

Ack.

-- 
Affijn, Ruud

"Gewoon is een tijger."
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'



------------------------------

Date: Tue, 28 Mar 2006 17:04:08 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Strange problem with IO::Socket::connected()
Message-Id: <44295068$0$31168$bb690d87@news.main-rheiner.de>

Manni Heumann wrote:
> Hi,
> 
> I'm currently working on a program that will connect to a server to retrieve 
> data. When connecting to the server, I check whether the return value of 
> connected is defined, otherwise an error is raised. Here's some code:
> 
> my $socket = IO::Socket::INET->new(
>                                    PeerAddr  => '127.0.0.1',
>                                    PeerPort  => 5555,
>                                    Type      => SOCK_STREAM,
>                                    Proto     => 'tcp',
>                                    Timeout   => 1,
>                                    );
> 
> if ( defined $socket && $socket->connected() ) {
> ...

A look into the IO::Socket module reveals that the connected method is 
only a disguised call to getpeername($socket) (see perldoc -f getpeername).

IIRC it will only return something useful if you have established a 
connection with either $socket->connect or $socket->accept.
I don't think it makes sense immediatly after IO::Socket::INET->new.

There are a number of reasons getpeername can fail. You have to look at 
the getpeername documentation for your OS.

Thomas

-- 
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 9099
***************************************


home help back first fref pref prev next nref lref last post